Plugin for promisifying Node.js style callback
s into Promise
s.
Compatible with all valid Promises/A+ implementations including bluebird, Q, etc..
const fs = require('fs');
// Just requiring the module will extend the existing Promise API
require('promise-from-callback');
Promise
.fromCallback(callback => fs.readFile('filename.txt'))
.then(buffer => buffer.toString().trim())
.fromCallback((filename, callback) => fs.readFile(filename, callback))
// ...
npm install promise-from-callback
<script type="application/javascript" src="promise-from-callback.js"></script>
Promise
.fromCallback(callback => fs.readFile('test.txt', callback))
.then(console.log)
Promise
.resolve('test.txt')
.fromCallback((filename, callback) => fs.readFile(filename, callback))
.then(console.log);