node-fs-writefile-promise

fs.writeFile wrapped in an ES6 Promise


Keywords
es6, fs, node-fs, write, file, writefile, write-file, promise, promises, then, thenable, catch, resolve, fulfill, fulfilled, reject, async, asynchronous, on
License
MIT
Install
npm install node-fs-writefile-promise@1.0.0

Documentation

node-fs-writefile-promise

NPM version Build Status Build status Coverage Status Dependency Status devDependency Status

fs.writeFile wrapped in an ES6 Promise

const writeFile = require('node-fs-writefile-promise');

writeFile('path/to/file', 'string or buffer data')
  .then(() => console.log('data written successfully to disk'))
  .catch(err => console.error(err.message));

A simple ES6 Promise-based wrapper around Node's built-in writeFile.

Installation

npm i node-fs-writefile-promise

npm install docs

API

const writeFile = require('node-fs-writefile-promise');

writeFile(file, data [, options])

file: String | Buffer | Integer filename or file descriptor
data: String | Buffer
options: Object | String (fs.writeFile options)

Returns: (Promise)

Once the file is written, the returned promise will be resolved with no arguments.

If there is an error, the returned promise will be rejected with an error as its first argument.

const writeFile = require('node-fs-writefile-promise');

const onFulfilled = () => console.log('File written successfully');
const onRejected = err => console.log('Cannot write to the file');

writeFile('path/to/file', 'string or buffer data').then(onFulfilled, onRejected);

writeFile('path/to/file', 'string or buffer data')
  .then(onFulfilled)
  .catch(onRejected);

License

Copyright (c) 2014 - 2016 Stephen Meyerhofer

Licensed under the MIT License.