Created
July 20, 2017 06:45
-
-
Save sandcastle/7f7660197e39cba46cfbf90c15be98f0 to your computer and use it in GitHub Desktop.
Async fs in node.js
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
| 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(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://2ality.com/2017/05/util-promisify.html