Skip to content

Instantly share code, notes, and snippets.

@bhubr
Created January 23, 2019 11:47
Show Gist options
  • Select an option

  • Save bhubr/c038d04c5fe4d4d540a83423c9cdb0dd to your computer and use it in GitHub Desktop.

Select an option

Save bhubr/c038d04c5fe4d4d540a83423c9cdb0dd to your computer and use it in GitHub Desktop.
Utiliser Bluebird pour "promisifier" un module entier
const fs = require('fs');
const Promise = require('bluebird');
Promise.promisifyAll(fs);
// Version callback
fs.readFile('package.json', (err, buf) => {
if(err) {
console.error(err);
return;
}
console.log(buf.toString());
});
// Version Promise (bluebird a ajouté des méthodes à fs en les suffixant par Async)
fs.readFileAsync('package.json')
.then(buf => buf.toString())
.then(console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment