Guided Notes

Modules: CommonJS & ES Modules

Splitting code into files, require/module.exports, import/export, built-in modules, and how Node resolves modules.

Why modules

Slide 1 / 5

A module is a file whose variables and functions are private unless exported. Modules keep code organised, reusable and testable: a pricing.js module, a db.js module, a routes/ folder.

Node supports two module systems: • CommonJS (CJS) — require() and module.exports; the traditional Node style. • ES Modules (ESM) — import and export; the JavaScript standard, also used in browsers.

← Introduction to Node.js