Promisify Node
Stable: 0.1.3
Maintained by Tim Branyen @tbranyen.
Wraps Node modules, functions, and methods written in the Node-callback style
to return Promises.
Install
npm install promisify-node
Examples
Wrap entire Node modules recursively:
var promisify = require("promisify-node");
var fs = promisify("fs");
fs.readFile("/etc/passwd").then(function(contents) {
console.log(contents);
});
Wrap a single function:
var promisify = require("promisify-node");
function async(callback) {
callback(null, true);
}
var wrap = promisify(async);
wrap().then(function(value) {
console.log(value === true);
});
Wrap a method on an Object:
var promisify = require("promisify-node");
var myObj = {
myMethod: function(a, b, cb) {
cb(a, b);
}
};
promisify(myObj);
myObj.myMethod({ msg: "Failure!" }, null).then(null, function(err) {
console.log(err.msg);
});
Tests
Run the tests after installing dependencies with:
npm test