How to find the location of installed npm packages?

In this tutorial, you will learn the path where NPM installs packages.

Using NPM, you can install packages in two ways, locally and globally.

Path of installed global npm packages

To find the path of installed global npm packages, run the npm list -g command.

The npm list command shows you two things:

  1. Path where global npm packages are installed.
  2. The versions of globally installed npm packages along with their dependencies.
$npm list -g
Location of installed global npm package

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:

npm list -g command

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.

  • On mac, global npm packages are installed in /usr/local/lib/node_modules.
  • On Windows 7, 8, 10, and above, global npm packages are installed at %USERPROFILE%\AppData\Roaming\npm\node_modules.
  • On Ubuntu, the location of installed global npm packages is /usr/local/lib/node_modules or /usr/local/lib/node.

Path of installed local npm packages

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.

Content of node_modules folder

Following is the content of package.json:

package.json file

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.

node_modules folder after installation

As you can see that NPM has installed the express package and its dependencies in the node_modules folder.

package.json file after installation

Also, the package.json file is updated by NPM, and the express package is mentioned in the file's dependencies section.

Recommended Posts