Skip to content

Instantly share code, notes, and snippets.

@mjuhl
Last active August 25, 2020 22:21
Show Gist options
  • Save mjuhl/54417b152b099764cf1fef8ef8d1172b to your computer and use it in GitHub Desktop.
Save mjuhl/54417b152b099764cf1fef8ef8d1172b to your computer and use it in GitHub Desktop.
Example REPL using async/await and util.promisify
// 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