Skip to content

Instantly share code, notes, and snippets.

@h4t0n
Forked from gergelyke/index.js
Created January 5, 2016 12:53
Show Gist options
  • Save h4t0n/0f856bf6bff68c40fe28 to your computer and use it in GitHub Desktop.
Save h4t0n/0f856bf6bff68c40fe28 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