-
-
Save brianleroux/b40852d9ef7ddb162d83 to your computer and use it in GitHub Desktop.
callback-with-promise
This file contains 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') | |
function readPackage (callback) { | |
//as of now we do not have default values in Node.js | |
callback = callback || function () {} | |
return new Promise((resolve, reject) => { | |
fs.readFile('./package.json', (err, data) => { | |
if (err) { | |
reject(err) | |
return callback(err) | |
} | |
resolve(data) | |
return callback(null, data) | |
}) | |
}) | |
} | |
module.exports.readPackage = readPackage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment