Last active
August 25, 2020 22:21
-
-
Save mjuhl/54417b152b099764cf1fef8ef8d1172b to your computer and use it in GitHub Desktop.
Example REPL using async/await and util.promisify
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
// use 'AsyncFunction' option | |
const { promisify } = require('util'); | |
const fs = require('fs'); | |
const writeFilePromise = promisify(fs.writeFile); | |
const readFilePromise = promisify(fs.readFile); | |
const filename = '/sv/clients/norway/test.txt'; | |
// write some text to a file | |
await writeFilePromise(filename, `It is currently ${new Date()}.`); | |
// read the text from the same file | |
return await readFilePromise(filename, 'utf-8'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment