Lesson content
Read, practise, then check your understanding
node:fs/promises offers Promise operations; callback and synchronous variants serve different contexts. Use node:path for platform-aware paths and URLs for module-relative resources.
Bounded file work
import { readFile, writeFile } from "node:fs/promises";
const text = await readFile(filePath, "utf8");
await writeFile(outputPath, text.toUpperCase(), { flag: "wx" });
Encoding returns strings; omitted encoding returns Buffer bytes. Streams process large data incrementally and propagate backpressure. Validate resolved user paths against an allowed root, expect races between check/use, set permissions deliberately, and handle partial failure. Important replacements should write a temporary sibling then rename where platform semantics permit.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.