Where does npm install the packages ?
When we install a package using npm you can perform two types of installation:
- Local Installation
- 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.
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
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
To List all the Global Packages in the system:
npm list -g --depth 0
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.
npm install <package-name>
Example to illustrate How to install the package locally in the system.
npm install express
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.