Last active
March 8, 2020 19:03
-
-
Save artiya4u/463c113a2e5cd6e303885af9759fb666 to your computer and use it in GitHub Desktop.
Use async function without callback.
This file contains 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 = '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