Skip to content

Instantly share code, notes, and snippets.

@alexaleluia12
Last active June 18, 2018 18:47
Show Gist options
  • Select an option

  • Save alexaleluia12/ab4bb715047437f940fe9aa4c836e525 to your computer and use it in GitHub Desktop.

Select an option

Save alexaleluia12/ab4bb715047437f940fe9aa4c836e525 to your computer and use it in GitHub Desktop.
assync and callback
// promises https://developers.google.com/web/fundamentals/primers/promises
// source: http://2ality.com/2017/05/util-promisify.html
const {promisify} = require('util');
const fs = require('fs');
const readFileAsync = promisify(fs.readFile);
const filePath = process.argv[2];
async function main() {
try {
const text = await readFileAsync(filePath, {encoding: 'utf8'});
console.log('CONTENT:', text);
}
catch (err) {
console.log('ERROR:', err);
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment