We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Lucio M. Tato • 3 years ago

on the first example, since you're returning a promise, there's no need to await on the last promise, better to return early

const fs = require('fs')

// promisify is a neat tool in the util module that transforms a callback function into a promise one
const { promisify } = require('util')
const writeFile = promisify(fs.writeFile)
const readFile = promisify(fs.readFile)

const writeAndRead = async () => {
await writeFile('./test.txt', 'Hello World')
return readFile('./test.txt', 'utf-8')

.then(content => console.log(content))