The Module System

Every topic in this chapter, free to read online. Work through them in order, or jump straight to the runtime detail you need.

Start with the first topic6.1 CJS require() Internals
06chapter
5topics
Freeonline

Topics

5 topics

CJS require() Internals

How Node.js require works internally through resolution, Module._load, source wrapping, compilation, module.exports, and require.cache.

Module Resolution

How Node.js resolves module specifiers through built-ins, relative paths, node_modules lookup, package.json main, exports, imports, and symlinks.

ES Modules

How ES Modules work in Node.js through static import/export syntax, module format detection, parse-link-evaluate phases, and live bindings.

CommonJS/ESM Interop

How CommonJS and ES Modules interoperate in Node.js through CJS namespaces, require(esm), conditional exports, and dual package design.

import.meta & ESM Caching

How import.meta, import.meta.url, import.meta.dirname, the ESM module cache, circular dependencies, and module state work in Node.js.