write-file
v1.0.0
Published
Writing a file to disk, creates intermediate directories in the destination path if they dont already exist.
Downloads
1,750
Readme
write-file
Writing a file to disk, creates intermediate directories in the destination path if they dont already exist.
Install
Install with npm
$ npm i write-file --save
Usage
For more use-cases see the tests
const writeFile = require('write-file')
API
writeFile
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 asopts.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')
})
// automatically writes a json files
writeFile('foo/qux/bar.json', { foo: 'bar' }, function (err) {
// if not `err`, file is written
})
Related
- dest: Customized implementation of the dest method from vinyl. | homepage
- then-read-json: Read JSON file using promises | homepage
- then-write-json: Write contents to JSON file using JSON.stringify and promises. Creating intermediate directories… more | homepage
- try-read-json: Fast, meaningful and correct try/catch flow for reading JSON with JSON.parse… more | homepage
- write-json: Write a JSON file to disk, also creates intermediate directories in the… more | homepage
- write: Write files to disk, creating intermediate directories if they don't exist. | homepage
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.