node package manager
Painless code sharing. npm Orgs help your team discover, share, and reuse code. Create a free org »

fs-writefile-promise

fs-writefile-promise version License

Promise version of fs.writefile:

Asynchronously writes data to a file, replacing the file if it already exists.

Build Status Downloads Code Climate Coverage Status Dependency Status Dependencies

Install

npm install --only=production --save fs-writefile-promise

Usage

I recommend using an optimized build matching your Node.js environment version, otherwise, the standard require would work just fine with any version of Node >= v4.0 .

/*
 * Node 7
 */
const write = require('fs-writefile-promise/lib/node7')
 
/*
 * Node 6
 */
const write = require('fs-writefile-promise/lib/node6')
 
/*
 * Node 4 (Default)
 * Note: additional ES2015 polyfills may be required
 */
var write = require('fs-writefile-promise')

API

write(filename, data [, options])

filename: String data String or Buffer options: Object Return: Object (Promise)

When it finishes, it will be fulfilled with the file name that was written to.

When it fails, it will be rejected with an error as its first argument.

write('/tmp/foo', 'bar')
  .then(function (filename) {
    console.log(filename) //=> '/tmp/foo' 
  })
 
  .catch(function (err) {
    console.error(err)
  })
})

options

The option object will be directly passed to fs.writefile.


©️ ahmadnassri.com  ·  License: ISC  ·  Github: @ahmadnassri  ·  Twitter: @ahmadnassri