Skip to content

Instantly share code, notes, and snippets.

@toboid
Created June 18, 2017 15:19
Show Gist options
  • Save toboid/934a311b5f782cbef3566e755d0d23c1 to your computer and use it in GitHub Desktop.
Save toboid/934a311b5f782cbef3566e755d0d23c1 to your computer and use it in GitHub Desktop.
util.promisify usage with async
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