Skip to content

Instantly share code, notes, and snippets.

@brianleroux
Forked from gergelyke/index.js
Created January 7, 2016 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save brianleroux/b40852d9ef7ddb162d83 to your computer and use it in GitHub Desktop.
Save brianleroux/b40852d9ef7ddb162d83 to your computer and use it in GitHub Desktop.
callback-with-promise
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