Stage 1 · Lesson 9 of 10
Modules and running code in Node.js
Run your code with node file.js from the terminal, not only in the browser, because tools, servers and tests all run in Node.js. Split code across files with ES : export a from one file and import it in another. In Node, add "type": "module" to package.json, or name files .mjs, to use import.
Older code uses require and module.exports (a system called ), which you will still meet in tutorials. Node also has built-in modules. import { readFileSync } from "node:fs" followed by JSON.parse(readFileSync("data.json", "utf8")) loads a file.
Reading JSON this way turns its text into a JavaScript object, and the same module handles of any kind. Expect an error when the file is missing or the JSON is invalid, and handle it with try and catch.
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
- CoursePaidGrokking JavaScript Fundamentals
Design Gurus · Beginner · $50
The language itself, closures and async included, with runnable exercises per lesson
- GuideFreeJavaScript.info
Ilya Kantor
Free: Part 1 is the most complete modern JavaScript tutorial, with tasks per chapter