Where does NPM Install the packages ?
Last Updated :
14 Aug, 2024
NPM is the default package manager for Node.js , and it is used to install, manage, and distribute JavaScript packages. When you add a package using NPM install, the location of the installed package depends upon whether the package is installed globally or locally.
Local Installation
Local installation happens when you run npm install package-name command.
When you install a package locally, it is placed in the node_modules directory within your project folder. This means the package is available only to that specific project and not accessible globally.
Steps to Install Package Locally
To install a package locally, you typically run:
npm install <package-name>
npm i <package-name> #shorthand
For example, to install the express package locally, you would run:
npm install express
Location of Locally Installed Packages
The packages are installed in the node_modules directory within your project folder, and the dependencies are listed in the package.json file . For instance, if your project structure is:

/my-project
|-- package.json
|-- node_modules/
| |-- express/
The express package will be installed in /my-project/node_modules/express.
Benefits of Local Installation
- Project-Specific : Dependencies are specific to the project, avoiding conflicts with other projects.
- Easier Version Control : You can easily manage different versions of packages for different projects.
- Portable : The entire project, including its dependencies, can be easily shared or moved.
Global Installation
The global installation takes place with the help of global attribute with npm install.
When you install a package globally, it is placed in a system-wide directory and made available from any location on your system. This is useful for installing tools and utilities that you want to use across multiple projects.
Step to Install Package Globally
To install a package globally, use the -g or –global flag:
npm install -g <package-name>
For example, to install the nodemon package globally, you would run:
npm install -g express

To List all the Global Packages in the system
npm list -g --depth 0
Output:

Location of Globally Installed Packages
The location of globally installed packages depends on your operating system and npm configuration:
- Windows : In windows, packages are installed in %APPDATA%\npm\node_modules .
- macOS and Linux : In mac or Linux packages are typically installed in /usr/local/lib/node_modules or a user-specific directory like ~/.npm-global .
You can find the exact location by running:
npm root -g
Benefits of Global Installation
- Accessible Everywhere : Packages are available system-wide and can be used in any project.
- Convenient for CLI Tools : Ideal for installing command-line tools that you use frequently.
Common Issues and Solutions
- Permission Issues : On Unix-like systems, you might encounter permission issues when installing globally. You can resolve this by configuring a custom directory for global installations as mentioned above.
- Version Conflicts : Different projects might require different versions of a package. Use local installations to isolate dependencies.
- Path Not Found : If globally installed packages are not found in the path, ensure your system’s PATH variable includes the global npm directory.
Conclusion
NPM installs packages locally in the node_modules directory within your project or globally in a system-wide directory (/usr/local/lib on macOS/Linux or %AppData%\npm on Windows) when using the -g flag. By mastering these installation methods, you can manage your Node.js projects more efficiently, avoid conflicts, and streamline your development workflow.
Similar Reads
How to Find the Version of Installed NPM Package?
Knowing the version of NPM installed on your system is important especially when working with specific versions of Node JS or when troubleshooting issues. This article provides instructions to check the version of NPM installed on your system. Prerequisites:Node JS Command Line InterfaceSteps To Fin
1 min read
How to Force an NPM Package to Install?
Forcing an NPM package to install can be necessary in cases where the dependencies of a package are in conflict or when you need to override existing constraints or force the installation of a specific version. Forcing an NPM package to install refers to using specific commands to bypass version con
3 min read
What is the --save option for npm install?
NPM, short for Node Package Manager, is the default package manager for NodeJS. It is a command-line utility that allows you to install, manage, and share packages or modules of JavaScript code. These packages can range from small utility libraries to large frameworks and can be easily integrated in
3 min read
How to list npm user-installed packages in Node.js?
What is Node.js? Node.js is an open source and cross-platform runtime environment for executing JavaScript code outside of a browser. Click here for more. What is npm? Here, "npm" stands for "Node Package Manager" which is the package manager for Node.js and serves as a command-line utility for inte
2 min read
How to Update Local Package in NPM?
Updating the local packages in NPM is a common task for the developers. Whether it is for bug fixes, new features, or security patches. Keeping your dependencies up to date is essential. These are the following approaches to updating the local package in NPM: Table of Content Update to the Latest St
4 min read
How to document NPM packages ?
In this article, we will see how to write the documentation of an NPM package. Documentation is an essential part of any NPM package because it gives an idea about the package method and how to use them. Good documentation makes your npm package popular npm packages. The Documentation of the npm pac
2 min read
How to Install Specific NPM Version ?
Node Package Manager (npm) is the default package manager for Node.js and is crucial for managing JavaScript libraries and frameworks. Sometimes, you may need to install a specific version of npm to ensure compatibility with certain projects, scripts, or tools. This article explains how to install a
2 min read
How to Find the Version of an Installed NPM Package in Node.js ?
NPM is the default package manager for Node.js. NPM manages both internal and external packages or modules used in various Node.js applications. The default packages in NPM may not fulfil all the needs of a developer, so we often require external packages. These can be installed either locally in a
2 min read
Top npm packages for node
NodeJS has become an effective tool for server-side development, thanks to its extensive ecosystem of npm packages. These packages offer a wide range of functionalities, from web frameworks to utility libraries, enabling users to build robust and scalable applications efficiently. In this article, w
4 min read
How to Install Yarn with NPM ?
Yarn is used for handling dependencies within JavaScript applications. It serves as both a package manager and a project manager. Whether you work on basic projects or complex industry-level monolithic repositories, whether you contribute to open-source initiatives or are part of an enterprise envir
4 min read