Promisify Node
Stable: 0.5.0
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 = ;var fs = ;// This function has been identified as an asynchronous function so it has// been automatically wrapped.fs;
Wrap a single function:
var promisify = ;{;}// Convert the function to return a Promise.var wrap = ;// Invoke the newly wrapped function.;
Wrap a method on an Object:
var promisify = ;var myObj ={;};// No need to return anything as the methods will be replaced on the object.;// Intentionally cause a failure by passing an object and inspect the message.myObj;
Wrap without mutating the original:
var promisify = ; var myObj = { ; }; // Store the original method to check latervar originalMethod = myObjmyMethod; // Now store the result, since the 'true' value means it won't mutate 'myObj'.var promisifiedObj = ; // Intentionally cause a failure by passing an object and inspect the message.promisifiedObj; // The original method is still intact;;
Tests
Run the tests after installing dependencies with:
npm test