Node Module - Node_modules directory

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





Discover More
CommonJs (NodeJs) - Require

The import functionality implementation of commonjs (and then node) is done via the require function require basically: reads a Javascript file (generally a CommonJs module but it may be any javascript...
How to resolve the SyntaxError: Cannot use import statement outside a module?

This article shows you how to resolve the syntax Error: Cannot use import statement outside a module.
Javascript - Module

functionality in Javascript. A module is different from a script file because: it defines a well-scoped object that does not pollute the global namespace. It list explicitly its dependencies Javascript...
Javascript - Yarn

Yarn is a package manager It aims to resolve two problems: to download the library only once by having a local repository to fix the code of the dependency. Library authors may have change the code...
Javascript - npm (Node package manager)

Npm is the package manager that is packaged/installed with a node installation. Automatically, with a node installation. Manually: -{VERSION}.tgz To update...
Javascript - pnpm

pnpm is a Javascript package manager pnpm differs from the other package manager via the structure of the node_modules folder where: the directory structure is flat with one dependency by directory...
Javascript Package - Package Manager

This article talks package manager in Javascript. They are the first component of the web toolchain as they permit to: declare package as dependency download and update package create a package...
Card Puncher Data Processing
Phantom Dependency

A is dependency used in a project: that is resolved (found) but is not declared as dependency in the project itself. If your project uses a dependency A that depends on B. The code of B is available....
What are npm scripts and how to use them ? The script property of Package.json

The scripts property in package.json are command lines that: * run in the same shell than your javascript package manager (npm, yarn, etc...) * search the command executable first in the local node...



Share this page:
Follow us:
Task Runner