Table of Contents

About

If the module identifier passed to require():

  • is not a core module
  • does not begin with '/', '../', or './',

then Node.js starts at the parent directory of the current module, and adds /node_modules, and attempts to load the module from that location.

If it is not found there, then it moves to the parent directory, and so on, until the root of the file system is reached.

Example

For example, if the file at /home/ry/projects/foo.js called require('bar.js')'', then Node.js 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

Documentation / Reference