CommonJS
Node.js's original module system, which loads code with require() and exports it with module.exports.
In more detail
CJS stands for CommonJS. It predates ECMAScript modules and is still used by many tools, so libraries often publish both formats. Its dynamic require calls make unused code harder for bundlers to remove.
Related terms
- ECMAScript modules — The standard JavaScript module system, written with import and export statements, used by browsers and modern tools.
- dual package — A package that ships both an ECMAScript module build and a CommonJS build, choosing between them through export conditions.
- Node.js — A program that runs JavaScript outside the web browser, used mainly to build servers, command-line tools and back-end services.
- module — A file of code whose functions, classes and variables other files can use by importing it.
- package type field — The "type" setting in package.json that makes Node.js treat the package's .js files as ES modules ("module") or CommonJS ("commonjs").
- NodeNext — A module and moduleResolution setting that makes TypeScript follow exactly the module rules of current Node.js.
- module (compiler option) — The compiler option that says which module system the output uses and, with NodeNext, how each file is treated.
- interop — Making two systems work together, such as ES modules importing CommonJS packages.
Taught in
- Component Packaging: Dual ESM/CJS Builds & Package Exports — Design Systems & Component Engineering
- Native Module Systems: ESM Loader Hooks vs CommonJS — Node.js Internals & Backend Services
- Why TypeScript: Contracts, Erased Types And Soundness — Production TypeScript
- tsconfig.json: target, lib, strict And NodeNext — Production TypeScript
- Type Aliases Versus Interfaces: Declaration Merging — Production TypeScript
- Union Types, Intersections And Property Conflicts — Production TypeScript
- Typeof Guards, Truthiness And Equality Narrowing — Production TypeScript
- The in Operator And Instanceof Narrowing — Production TypeScript
- Assertion Signatures: asserts condition And Invariants — Production TypeScript
- Exhaustive Narrowing With never In Production Handlers — Production TypeScript
- Why Generics: Functions, Identities And Type Variables — Production TypeScript
- Generic Constraints: extends, keyof And Indexed Access — Production TypeScript
- Const Type Parameters: Retaining Literal Types In Functions — Production TypeScript
- Core Utilities: Partial, Required, Readonly, Pick And Omit — Production TypeScript
- Function Utilities: ReturnType, Parameters And Constructor — Production TypeScript
- ECMAScript Modules, CJS Interop And verbatimModuleSyntax — Production TypeScript
- The satisfies Operator: Safe Validation Without Widening — Production TypeScript