Created
January 23, 2019 11:47
-
-
Save bhubr/c038d04c5fe4d4d540a83423c9cdb0dd to your computer and use it in GitHub Desktop.
Utiliser Bluebird pour "promisifier" un module entier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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