CommonJS
CommonJS is a JavaScript module-system specification that defines how modules export and load values, traditionally using synchronous require calls and module.exports assignments.
JavaScript in Depth
A module system specification for JavaScript based on synchronous loading and the require/export model.
- How it is used
- Frames Node.js file loading and scheduling as context-dependent rather than language-only behavior.
- How deep it goes
- Explains file classification and queue-draining order, but does not detail require or export implementation.
- Examples
- Uses queueMicrotask, process.nextTick, timers, promises, and extension-based reruns to expose differing output orders.
- What you can do after
- Evaluate/understand how Node.js classification changes module loading and asynchronous execution order.
The Joy of JavaScript
A server-side JavaScript module specification that defines modules using synchronous loading and the require/module.exports convention.
- How it is used
- Deploys programmatic, conditional module loading and API consumption through require and exported values.
- How deep it goes
- Explains dynamic loading, exports, copied destructured values, and conditional selection, while contrasting but not fully detailing ESM internals.
- Examples
- Uses calculator exports, Transaction loading, validation imports, filesystem imports, and feature-flagged wallet implementations.
- What you can do after
- Apply it via Node.js by defining exports, consuming modules with require, and selecting dependencies conditionally.
Secrets of the JavaScript Ninja, Second Edition
A JavaScript module system that defines reusable modules with synchronous loading, commonly used in Node.js.
- How it is used
- Organizes growing JavaScript applications into reusable modules with public interfaces, particularly in server-side environments.
- How deep it goes
- Shows module definition and consumption through require and module.exports, but leaves project setup beyond scope.
- Examples
- Uses a jQuery-dependent click-counter module and a require call that invokes its exported method.
- What you can do after
- Build it from scratch using require for dependencies and module.exports for a public interface.
Read how Secrets of the JavaScript Ninja, Second Edition explains CommonJS →
Secrets of the JavaScript Ninja, Third Edition
CommonJS is a JavaScript module-system specification traditionally based on synchronous require calls and module.exports assignments.
- How it is used
- Provides a practical module system for Node.js and a format used by packages that may be bundled for browser use.
- How deep it goes
- Explains module exports, dynamic synchronous loading, and ESM interoperability limits.
- Examples
- Uses a runtime-built `require()` path to demonstrate dynamic module selection.
- What you can do after
- Understand how dynamic synchronous loading affects CommonJS interoperability with ESM, especially for top-level await.
Read how Secrets of the JavaScript Ninja, Third Edition explains CommonJS →
Essential TypeScript 5, Third Edition
CommonJS is a JavaScript module system specification for defining and loading modules, especially in server-side environments.
- How it is used
- Organizes multi-file JavaScript applications and supplies Node.js with a supported module format.
- How deep it goes
- Explains its history, configuration, and TypeScript-generated require output, but does not detail the full CommonJS specification.
- Examples
- Uses split TypeScript files, an exported sum function, generated require code, package.json settings, and a Total: 600 output.
- What you can do after
- Operate/configure Node.js projects by selecting CommonJS and recognizing TypeScript output that uses require and exports.
Read how Essential TypeScript 5, Third Edition explains CommonJS →
Also covered in
- Fast by DefaultIn early access (MEAP)
What to know first
- moduleA module is a cohesive unit of code or computation that groups related functionality within a larger system and defines a scope or boundary for organizing or sharing it.
- promiseA JavaScript Promise is an object representing the eventual completion or failure of an asynchronous operation and its resulting value or reason.
- AMDAsynchronous Module Definition (AMD) is a JavaScript module format that specifies modules and their dependencies for asynchronous loading.
Related concepts
- AMDalternative to · Asynchronous Module Definition (AMD) is a JavaScript module format that specifies modules and their dependencies for asynchronous loading.
- Node.jsused by · Node.js is an open-source JavaScript runtime built on the V8 engine for executing JavaScript outside web browsers.
- modulealternative to · A module is a cohesive unit of code or computation that groups related functionality within a larger system and defines a scope or boundary for organizing or sharing it.
- requireuses · require is a CommonJS function that synchronously loads a module and returns its exported value.
- ECMAScript modulealternative to · An ECMAScript module is a separately scoped JavaScript unit whose dependencies and shared bindings are declared with import and export syntax.
Questions about CommonJS
What is CommonJS?
CommonJS is a JavaScript module-system specification that defines how modules export and load values, traditionally using synchronous require calls and module.exports assignments.
Which Manning books explain CommonJS?
JavaScript in Depth, The Joy of JavaScript, Secrets of the JavaScript Ninja, Second Edition, Secrets of the JavaScript Ninja, Third Edition and Essential TypeScript 5, Third Edition.
What should I know before learning CommonJS?
Manning books that teach CommonJS usually introduce module, promise, AMD and ECMAScript 2015 first.
What is the difference between CommonJS and AMD?
CommonJS is a JavaScript module-system specification that defines how modules export and load values, traditionally using synchronous require calls and module.exports assignments. Asynchronous Module Definition (AMD) is a JavaScript module format that specifies modules and their dependencies for asynchronous loading.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.




