require()
is not a native module,
and does not begin with '/'
, '../'
, or './'
, then node starts at the
parent directory of the current module, and adds /node_mo1dules
, and
attempts to load the module from that location.
For example, if the file at '/home/ry/projects/foo.js'
called
require('bar.js'
), then node would look in the following locations,
in this order:
/home/ry/projects/node_modules/bar.js /home/ry/node_modules/bar.js /home/node_modules/bar.js /node_modules/bar.js
This allows programs to localize their dependencies, so that they do not clash.
Casiano Rodriguez León 2015-01-07