Last active
June 18, 2018 18:47
-
-
Save alexaleluia12/ab4bb715047437f940fe9aa4c836e525 to your computer and use it in GitHub Desktop.
assync and callback
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
| // 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