module
implements require
function.
Since require
function is implicitly passed to user code, user do not need to import it explicitly.
id : String
- module name to be loaded
load the module named 'id'
require
function finds modules in the order of
- caller's directory of
require
function - node_modules under the caller's directory
- $HOME/node_modules
For each directory in search paths above,
- If native module named 'id' exists, load it and return.
- If id.js file exists, load it and return.
- If a directory id exists, load it as an package and return.
For a given id, if a directory id exists, module system consider the directory as a package.
- if 'id/node_modules/package.json' contains 'main' property, load the file named main property.
- if either id/node_modules/package.json or main property exists, load index.js