write-file-bluebird

1.0.5 • Public • Published

write-file-bluebird

NPM version Build Status Coverage Status NSP Status

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
    }
  );

license

MIT License

Package Sidebar

Install

npm i write-file-bluebird

Weekly Downloads

8

Version

1.0.5

License

MIT

Last publish

Collaborators

  • dentous