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
Loads the module named 'id'
require function finds modules in the order of
- current working directory
- node_modules directory under current working directory
- $HOME/node_modules
- $NODE_PATH/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