FS Promises with Then and Catch — a practical guide to fs promises then catch with clear examples you can reuse in real projects.
FS Promises with Then and Catch — 14/55 in the Node.js series. Full playlist companion: Node.js complete course on YouTube. Prefer one article? Read the complete Node.js tutorial.
Short description
`fs.promises` returns Promises instead of using callbacks, which reads more linearly when chained with then/catch.
fs.promises + then/catch
const fs = require('fs').promises;
fs.writeFile('demo.txt', 'Promise style')
.then(() => fs.readFile('demo.txt', 'utf8'))
.then((data) => console.log(data))
.catch((err) => console.error(err));