Created
June 18, 2017 15:19
-
-
Save toboid/934a311b5f782cbef3566e755d0d23c1 to your computer and use it in GitHub Desktop.
util.promisify usage with async
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 readFile = promisify(fs.readFile); | |
// await can only be used within an async function | |
(async () => { | |
try { | |
const fileContents = await readFile('./foo.txt'); | |
console.log(fileContents.toString()); | |
} catch (ex) { | |
ex => console.error(error) | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment