I find the "Do not block the event loop" example terrible:
const fs = require('fs');
fs.readFile('/file.txt', (err, data) => {
// perform actions on file content
fs.unlink('/file.txt', (err) => {
if (err) throw err;
});
});
This comes right after a section about "use flat promise chains" and is also vulnerable to leaving file.txt behind if the "perform actions" part throws. Much better example imho: const fs = require('fs/promises');
const data = await fs.readFile('/file.txt');
try {
// Do something with the data
} finally {
await fs.unlink('/file.txt');
}