write-file-bluebird
v1.0.5
Published
promise wrapper for node’s fs.writeFile()
Downloads
2
Readme
write-file-bluebird
promise wrapper for node’s fs.writeFile().
wraps node’s fs.writeFile()
, in a bluebird promise that resolves with true
if successful, or rejects with the Error
returned by fs.writeFile()
; both results need to be handled by the code calling this function.
table of contents
installation
npm install write-file-bluebird
usage
writeFile( file, data[, options] )
@param {string|buffer|number} file filename or file descriptor
@param {string|buffer} data
@param {object|string} [options]
@param {string|null} [options.encoding = 'utf-8']
@param {number} [options.mode = 0o666]
@param {string} [options.flag = 'w']
@returns {Promise}
default
var data = JSON.stringify( { test: "content" } );
var writeFile = require( 'write-file-bluebird' );
writeFile( 'test.json', data )
.then(
function( result ) {
// handle success
}
)
.catch(
function( err ) {
// handle error
}
);
using node’s path module
the path __dirname/test
must exist in order to create the file test.json
in it
var path = require( 'path' );
var data = JSON.stringify( { test: "content" } );
var writeFile = require( 'write-file-bluebird' );
var file = path.join( __dirname, 'test', 'test.json' );
writeFile( file, data )
.then(
function( result ) {
// handle success
}
)
.catch(
function( err ) {
// handle error
}
);