Promisify a callback-style function
$ npm install --save pify
var fs = require('fs');
var pify = require('pify');
pify(fs.readFile)('package.json', 'utf8').then(function (data) {
console.log(JSON.parse(data).name);
//=> 'pify'
});
// Wrap entirel modules
var promiseFs = pify.all(fs);
promiseFs.readFile('package.json', 'utf8').then(function (data) {
console.log(JSON.parse(data).name);
//=> 'pify'
});Returns a promise wrapped version of the supplied function.
If the callback of the supplied function gets more than two arguments the result will be an array.
Type: function
Callback-style function.
Returns a promise wrapped version of the module.
Type: object
A module whose methods you want to transform into promises.
Type: function
Custom promise module to use instead of the native one.
Check out pinkie-promise if you need a tiny promise polyfill.
MIT © Sindre Sorhus