Skip to content

Instantly share code, notes, and snippets.

@artiya4u
Last active March 8, 2020 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artiya4u/463c113a2e5cd6e303885af9759fb666 to your computer and use it in GitHub Desktop.
Save artiya4u/463c113a2e5cd6e303885af9759fb666 to your computer and use it in GitHub Desktop.
Use async function without callback.
const {promisify} = require('util');
const fs = require('fs');
const readFileAsync = promisify(fs.readFile);
const filePath = 'index.js';
async function main() {
try {
let text = await readFileAsync(filePath, {encoding: 'utf8'});
console.log(text);
} catch (error) {
console.log(error);
}
}
main().then();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment