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
.
npm i node-fs-writefile-promise
const writeFile = require('node-fs-writefile-promise');
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);
Copyright (c) 2014 - 2016 Stephen Meyerhofer
Licensed under the MIT License.