CommonJS modules are JavaScript files that are loaded using the require(String)
function. This function returns a module object, which wraps the script code from the file. Within a module
implementation, the module object can be accessed via the module variable.
A module has a unique absolute id. The same module may be resolved by require(String)
for different path arguments, like relative paths (starting with ”./” or ”../”), or absolute paths. See the
documentation of require for more details about the lookup procedure.
Every module object has an exports property which can be used by the module implementation to expose its
public functions or properties. Only functions and properties that are explicitly exported are accessible from other
modules, all others are private and not visible. For convenience, the global exports variable
is by default also initialized with the module.exports property of the current module.
In the most simple case, module elements can be exposed by adding them to the exports object, like:
The absolute, normalized id of the module, which uniquely identifies it. A call to the
global.require(String) function with this id would resolve this module.
The module (if exists) that is overridden by this module. The super module would have the same path as the
current module but its code location would be checked later in the lookup sequence. This property is useful to
reuse functionality implemented in overridden modules.