Open In App

Where does npm install the packages ?

Last Updated : 14 Jul, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

NPM (Node Package Manager) is the default package manager for Node.js and is written entirely in Javascript. In this article, we will see Where does npm install the packages.

When we install a package using npm you can perform two types of installation:

  1. Local Installation
  2. Global Installation

Let’s understand each of them in detail.

1. Global Installation of packages: The global installation of dependencies in Node.js is putting global packages in a single place in the system exactly where depends on your setup regardless of where you run the command npm install -g <package-name> to install dependencies.

 

Syntax:

run npm install -g <package-name>

Here g denotes a global mode of a variable.

Example to illustrate How to install package globally in the system.

Write this command in the console.

 npm install -g express

Output:

Path of Global Packages in the system: Global modules are installed in the standard system in root location in system directory  /usr/local/lib/node_modules project directory.

 

Command to print the location on your system where all the global modules are installed.

npm root -g

Output:

C:\Users\Pallavi\AppData\Roaming\npm\node_modules

To List all the Global Packages in the system:

npm list -g --depth 0 

Output:

2. Local Installation of Packages: Local packages are installed in the directory where you run npm install <package-name> and they are put in the node_modules folder under this directory.

Syntax:

npm install <package-name>

Example to illustrate How to install the package locally in the system.

npm install express

Output:

Path of Local Packages in the system: These all are installed in package.json file of the project locally as shown in the below image.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads