Node Module - Node_modules directory


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.


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:


Documentation / Reference

Powered by ComboStrap