Created
November 11, 2017 08:12
-
-
Save vitkarpov/a893e4c8cf8315bbb406a7958ab424c4 to your computer and use it in GitHub Desktop.
Example of util.promisify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @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