Skip to content

Instantly share code, notes, and snippets.

@rbren
Last active September 21, 2017 17:41
Show Gist options
  • Save rbren/541e7e83fa42453e8cbed56cc3368794 to your computer and use it in GitHub Desktop.
Save rbren/541e7e83fa42453e8cbed56cc3368794 to your computer and use it in GitHub Desktop.
function readFilePromise(filename) {
return new Promise((resolve, reject) => {
fs.readFile(filename, 'utf8', (err, data) => {
if (err) reject(err);
else resolve(data);
})
})
}
readFilePromise('index.html')
.then(data => console.log(data))
.catch(e => console.log(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment