Programming foundations

Stage 1 · Lesson 9 of 10

Modules and running code in Node.js

Your first language

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

  • CoursePaid
    Grokking JavaScript Fundamentals

    Design Gurus · Beginner · $50

    The language itself, closures and async included, with runnable exercises per lesson

  • GuideFree
    JavaScript.info

    Ilya Kantor

    Free: Part 1 is the most complete modern JavaScript tutorial, with tasks per chapter

Practise

  • Small exercises in your language track, with free feedback from a human mentor

  • Foundations path: the JavaScript basics lessons and the exercises repo with tests

Keep handy

  • The JavaScript reference: look up every array and string method here

Mark this stage as not done?