In this tutorial, you will learn the path where NPM installs packages.
Using NPM, you can install packages in two ways, locally and globally.
To find the path of installed global npm packages, run the npm list -g
command.
The npm list command shows you two things:
$npm list -g
As you can see, the first line of the output shows the path on your computer where global npm packages are installed.
If you run the npm list -g
command on NPM version 8.x, then you will get the following output:
No matter which version of NPM you use to run this command, the first line of the output is the path where global npm packages are installed.
/usr/local/lib/node_modules
.%USERPROFILE%\AppData\Roaming\npm\node_modules
./usr/local/lib/node_modules
or /usr/local/lib/node
.Local npm packages are installed to the node_modules
folder which is present in the root directory of the project.
Local npm packages are installed in the node_modules
folder, which resides in the project's root directory.
Suppose we want to install the express
module in your project. Before we install it, let's look at our project's node_modules
folder and package.json
file.
The following is the screenshot of the node_modules
folder of your project.
Following is the content of package.json
:
Now, let's install the express
package by running the following command:
$npm install express
After running this command, let's see what changes are made to the node_modules
folder and package.json
file by NPM.
As you can see that NPM has installed the express
package and its dependencies in the node_modules
folder.
Also, the package.json
file is updated by NPM, and the express
package is mentioned in the file's dependencies section.