Whenever npm installs a package, it looks into the package.json
file. If it finds the bin key-value pair, it installs those executables in the bin folder, and the package in the node_modules folder.
Now, depending on the installation type, the folder is location will vary. npm installs packages locally and globally. The basic command to execute is the same; the only difference is passing the -g
argument to install the package globally.
npm install lodash -g
In the case of global installation, the executables are installed in prefix_config/.bin
, and the package is placed into prefix_config/lib/node_modules
.
Prefix is where npm stores global packages, and it is defined in the npm config. Different operating systems have different prefixes. To find the prefix:
npm root -g
For example, in Ubuntu, the prefix is /usr
, so npm will install executables into /usr/.bin
and packages into /usr/lib/node_modules
.
In contrast to global installations, local installations place executables and packages within the directory containing the package.json
file. When the npm start
script is executed, it searches for the specific executable in the local installation.