Guided Notes
The File System Module
Reading and writing files with fs/promises, JSON files, appending, folders, checking existence, and handling errors safely.
Three styles of fs
Slide 1 / 4The fs module offers the same operations in three styles: • Promise API: import { readFile } from "node:fs/promises" — use with async/await (recommended). • Callback API: fs.readFile(path, "utf8", (err, data) => …). • Sync API: fs.readFileSync(path, "utf8") — blocks the event loop; fine for scripts and startup, avoid in servers handling requests.
