Writing a file to disk, creates intermediate directories in the destination path if they dont already exist.
![dependency status](https://img.shields.io/david/tunnckoCore/write-file.svg)
Install
Install with npm
$ npm i write-file --save
Usage
For more use-cases see the tests
const writeFile = require('write-file')
API
Writes a file to disk with support for creating intermediate directories and JSON files.
Params
<fp>
{String|Buffer|Number}: filepath to the new filedata
{String|Buffer|Object}: if object, JSON.stringify and writes it[options]
{Object|String}: passed to mkdirp too; if string, treats it as opts.encoding
callback
{Function}: done callback
Example
var writeFile = require('write-file')
writeFile('foo/bar/baz/qux.txt', 'some contents', function (err) {
if (err) return console.log(err)
console.log('file is written')
})
writeFile('foo/qux/bar.json', { foo: 'bar' }, function (err) {
})
Related
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.
![tunnckoCore github](https://img.shields.io/badge/github-@tunnckoCore-4183c4.svg)