node-fs-writefile-promise
v1.0.0
Published
fs.writeFile wrapped in an ES6 Promise
Downloads
27
Maintainers
Readme
node-fs-writefile-promise
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
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.