Skip to content

Instantly share code, notes, and snippets.

@sandcastle
Created July 20, 2017 06:45
Show Gist options
  • Select an option

  • Save sandcastle/7f7660197e39cba46cfbf90c15be98f0 to your computer and use it in GitHub Desktop.

Select an option

Save sandcastle/7f7660197e39cba46cfbf90c15be98f0 to your computer and use it in GitHub Desktop.
Async fs in node.js
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();
@sandcastle

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment