Stage 6 · Lesson 3 of 8
Files and JSON in Node.js
is native to JavaScript, so parsing JSON takes one call. JSON.parse turns text into objects and arrays, and JSON.stringify(data, null, 2) turns them back into readable text. For in , use the version built on : import { readFile, writeFile } from "node:fs/promises", then await readFile(path, "utf8").
Promises are values that arrive later, and await waits for one. A missing file rejects with an error whose code is "ENOENT". You can catch that to create a starter file on the first run.
JSON.parse throws a SyntaxError on invalid text. Validate what you load, because a missing property gives undefined rather than an error, and the bug shows up much later. Keep file code in its own module, so the core logic works on plain objects.
A question to check yourself, an AI practice session and 3 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- GitHub repoFreeProject Based Learning
Community maintained · Beginner
Follow one guided build in your language, then build your own without a guide
- BookFreeEloquent JavaScript
Marijn Haverbeke · Intermediate
Free: the project chapters (a robot, a programming language, a pixel editor) show real structure
Keep handy
Also worth your time
How to present each project: the problem, stack, challenges and results
- Build Your Own XGo deeper
When you want a harder build: a shell, a key-value store or a tiny Git, from scratch