You can convert a single function with a callback argument to a Promise
-returning version with Promise.promisify
, so this:
const fs = require("fs"); fs.readFile("foo.txt", (err, data) => { if(err) throw err; console.log(data); });
becomes:
const promisify = require("bluebird"); const readFile = promisify(require("fs").readFile)); readFile("foo.txt").then(console.log); // promisified version