Skip to content

Chapter 30 of 33

Node.js and Modules

Understand the Node runtime, ESM, CommonJS, resolution, process, and environments.

42 minutes 10 quick checksBy Subha Prasad
Lesson 30 of 33Course navigation

Lesson content

Read, practise, then check your understanding

Node.js runs JavaScript outside the browser with event-driven I/O and built-in modules. It provides process, buffers, streams, filesystem, networking, and worker APIs but no page DOM.

Module choices

// ESM
import { readFile } from "node:fs/promises";
export async function load(path) { return readFile(path, "utf8"); }

// CommonJS legacy shape
// const { readFile } = require("node:fs/promises");

Package type, .mjs/.cjs extensions, and exports fields control interpretation and resolution. Avoid mixing systems casually. Read configuration from validated environment variables, handle signals for graceful shutdown, and never block the event loop with large synchronous operations in request paths.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement best describes Node.js?
Which JavaScript term matches this description: A server-side JavaScript runtime built around an event-driven I/O model.
Which statement best describes CommonJS?
Which JavaScript term matches this description: The require/module.exports module system historically used by Node.
Which statement best describes ES module in Node?
Which JavaScript term matches this description: A standards-based module using import/export and Node resolution rules.
Which statement best describes package type?
Which JavaScript term matches this description: The package.json type field influencing .js module interpretation.
Which statement best describes process?
Which JavaScript term matches this description: Node's global interface for arguments, environment, signals, and lifecycle.

0 of 10 checks passed

Your progress is saved on this device.