-
-
Save h4t0n/0f856bf6bff68c40fe28 to your computer and use it in GitHub Desktop.
callback-with-promise
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') | |
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