/

Where does npm install the packages?

Where does npm install the packages?

How to Find Out Where npm Installs the Packages

If you’re new to npm and want to learn more about it, check out the npm guide which covers all the basics.

When you install a package using npm (or yarn), there are two types of installation you can perform: a local install or a global install.

By default, when you run the npm install command like this:

1
npm install lodash

The package is installed in the current file tree under the node_modules subfolder. At the same time, npm adds an entry for lodash in the dependencies property of the package.json file in the current folder.

On the other hand, a global installation is performed by using the -g flag:

1
npm install -g lodash

In this case, npm installs the package in a global location. But where exactly is that location?

To find out, you can use the npm root -g command. The output will show you the exact location on your machine.

  • On macOS or Linux, this location could be /usr/local/lib/node_modules.
  • On Windows, it could be C:\Users\YOU\AppData\Roaming\npm\node_modules.

However, if you use nvm to manage different Node.js versions, the location may be different. For example, if you use nvm, the packages location could be shown as /Users/flavio/.nvm/versions/node/v8.9.0/lib/node_modules.

tags: [“npm”, “package installation”, “local install”, “global install”]