Please use util.promisify
instead of fs-promisify
if your node.js version >= 8.
fs-promisify
the module that convert node fs callback function to return a promise.
install
npm install fs-promisify
usage
const fs = require('fs');
const promisify = require('fs-promisify');
promiseify(fs.readFile)(filename, 'utf-8')
.then(data => {
console.log(data.toString());
})
.catch(error => {
console.error(error);
});
support
- fs.access
- fs.appendFile
- fs.chmod
- fs.chown
- fs.close
- fs.fchmod
- fs.fchown
- fs.fstat
- fs.fsync
- fs.ftruncate
- fs.futimes
- fs.lchmod
- fs.lchown
- fs.link
- fs.lstat
- fs.mkdir
- fs.mkdtemp
- fs.open
- fs.read
- fs.readdir
- fs.readFile
- fs.readlink
- fs.realpath
- fs.rename
- fs.rmdir
- fs.stat
- fs.symlink
- fs.truncate
- fs.unlink
- fs.unwatchFile
- fs.utimes
- fs.write
- fs.writeFile