Skip to content

Instantly share code, notes, and snippets.

@vitkarpov
Created November 11, 2017 08:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vitkarpov/a893e4c8cf8315bbb406a7958ab424c4 to your computer and use it in GitHub Desktop.
Save vitkarpov/a893e4c8cf8315bbb406a7958ab424c4 to your computer and use it in GitHub Desktop.
Example of util.promisify
// @see 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];
readFileAsync(filePath, { encoding: 'utf8' })
.then((text) => {
console.log('CONTENT:', text);
})
.catch((err) => {
console.log('ERROR:', err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment