In CommonJS, `module.exports` names the value a module exposes as its public API. A clear interface lets other code use the module’s functionality while keeping implementation details hidden and protected from unwanted changes. section 11.1
Module.exports
The CommonJS property whose assigned value is exposed as a module's public API.
How Secrets of the JavaScript Ninja, Second Edition covers it
- How deep it goes
- Frames module interfaces and hidden internals, but does not detail `module.exports` assignment mechanics.
- What you can do after
- Understand how a CommonJS module’s public interface separates usable functionality from hidden implementation details.
- How it connects
- Connects CommonJS with JavaScript modules, objects, closures, immediate functions, and AMD.
Related concepts
- import/export syntaxequivalent to · Module import and export syntax declares dependencies between modules and makes selected bindings available to other modules.
- exportsequivalent to · In CommonJS, exports is a module-local variable that initially references the module's export object and can be used to define exported members.
- CommonJSpart of · CommonJS is a JavaScript module-system specification that defines how modules export and load values, traditionally using synchronous require calls and module.exports assignments.
- dynamic module systemused by · A module system in which dependencies and module interfaces are determined programmatically at runtime rather than by static language syntax.
This explainer was generated by Manning's knowledge graph from the text of Secrets of the JavaScript Ninja, Second Edition. The section links point to the parts of the book it draws on.
