Core Module FS (File System) — a practical guide to Node.js fs module with clear examples you can reuse in real projects.
Core Module FS (File System) — 10/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` is a core Node.js module for filesystem operations. You can use callback, sync, or promise-based APIs.
Write and read a file (callback)
const fs = require('fs');
fs.writeFile('hello.txt', 'Hello Node', (err) => {
if (err) throw err;
fs.readFile('hello.txt', 'utf8', (err, data) => {
if (err) throw err;
console.log(data);
});
});