AI Workshop: learn to build apps with AI →
npm: Where does npm install the packages?

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


Read the npm guide if you are starting out with npm, it will go into a lot of the basic details.

When you install a package with npm (or yarn), you can do two types of installation:

  • a local install
  • a global install

By default, when you type an npm install command, like:

npm install lodash

the package is installed in the current directory, under the node_modules subfolder.

As this happens, npm also adds the lodash entry in the dependencies property of the package.json file present in the current folder.

A global installation is performed using the -g flag:

npm install -g lodash

When this happens, npm won’t install the package under the local folder, but instead, it will use a global location.

Where, exactly?

The npm root -g command will tell you where that exact location is 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

If you use nvm to manage Node.js versions, however, that location would differ.

If you use nvm to manage Node versions, the path is under your nvm directory (e.g. ~/.nvm/versions/node/v8.9.0/lib/node_modules).

Lessons in this unit:

0: Introduction
1: How to use or execute a package installed using npm
2: npm dependencies and devDependencies
3: How to fix the "Missing write access" error when using npm
4: npm can install packages in the parent folder
5: Install an older version of an npm package
6: Find the installed version of an npm package
7: How to test an npm package locally
8: npm global or local packages
9: What are peer dependencies in a Node module?
10: `npm run dev` is a long-running program
11: Semantic Versioning using npm
12: Uninstalling npm packages with `npm uninstall`
13: An introduction to the npm package manager
14: The npx Node Package Runner
15: The package.json guide
16: The package-lock.json file
17: What is pnpm?
18: Should you commit the node_modules folder to Git?
19: Update all the Node dependencies to their latest version
20: ▶︎ Where does npm install the packages?
21: Bumping Node.js dependencies
22: Run package.json scripts upon any file changes in a folder