Promises are a great way to improve your codebase by preventing callback hell and making asynchronous code look more readable. Working with files in Node.js can be done with callbacks if you’d like, but promises can make it easier. In this post, we’ll go over how to read and write files with promises in Node.js.
const {promises: {readFile}} = require("fs");
const content = await readFile('./test.txt', {encoding:'utf8', flag:'r'});