Node Module - Node_modules directory

> (World Wide) Web - (W3|WWW) > Javascript (Js|ECMAScript) > Node.js > Node - Module (ie NPM Module)

1 - 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.

Advertising

3 - 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

4 - Documentation / Reference

web/javascript/node/module/node_modules.txt · Last modified: 2019/02/16 17:40 by gerardnico