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)
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')
}
writeAndRead()
.then(content => console.log(content))