Where does npm install packages? Find the install path

Posted on May 30, 2022

Finding the install path of npm packages installed on your computer

The npm packages installed locally will always be installed on the node_modules/ folder right in your current working directory.

For example, when you’re on a directory called project/ from the terminal, then it will be inside the project/node_modules folder.

The npm install command will find the node_modules/ folder on the current directory. It will create one when it doesn’t exist.

Globally installed npm packages location

Globally installed npm packages usually follow the installation path of your npm module.

The easiest way to know where the global modules are installed is to run the npm list -g command.

The command shows the path to your global node_modules/ folder:

$ npm list -g
/usr/local/lib
└── (empty)

On macOS computers, npm will be installed under /usr/local/bin/npm soft link path.

The actual path to the npm package is under /usr/local/lib/node_modules. Any globally installed packages will end up in that path as well.

On Linux computers, you’ll find the global install location on /usr/local/lib/node_modules as well.

On Windows computers, global npm packages should be installed under the roaming/ folder.

The example path is as follows:

%USERPROFILE%\AppData\Roaming\npm\node_modules

Like in Unix-based systems, you can use the npm list -g command to find your global node_modules/ folder location:

$ npm list -g
C:\Users\nathan\AppData\Roaming\npm
└── (empty)

Now you’ve learned how to find where npm packages are installed globally.

Global install using NVM

If you’re using NVM on your computer, then the packages you installed globally will be placed under the active Node version you’re using.

You can find the global node_modules/ folder location using the npm list -g command.

For example, suppose you’ve installed NVM on Windows under D:\ drive as shown below:

D:/programs/nvm
├── v10.24.1
├── v12.22.12
└── v16.13.0

When you’re using Node v16.13.0 as the active version, then a global install will put the package under the v16.13.0/node_modules folder.

The same goes when you’re using Unix-based systems like Linux and macOS.

The installation directory of nvm may change to your Users/ folder as shown below:

$HOME/.nvm/versions/node/
├── v10.24.1
├── v12.22.12
└── v16.13.0

The global packages will be installed under the active Node version lib/node_modules folder.

The absolute path looks as follows:

$HOME/.nvm/versions/node/v16.13.0/lib/node_modules

The $HOME variable points to your user directory in the system. You can also use the where nvm command to find your NVM installation location.

Now you’ve learned where npm installs packages on your computer. Always remember that you can find the global installation path using the npm list -g command. 👍

Level up your programming skills

I'm sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.