How to Check if NPM Package is Installed Locally or Globally
In this post, we'll learn how to check where a npm package is installed, whether it is installed locally or globally on your system.
Locally Installed NPM Packages
You can view the list of locally installed npm packages by running the npm list
command inside your project's root directory.
BASHnpm list
This does the equivalent of listing out the packages in your package.json
file.
If you want to view your locally installed packages without their dependencies, you can run the command while specifying a depth of 0
.
BASHnpm list --depth=0
If you want to check your local packages for a specific package, you can run the command with the package name as the first argument.
BASHnpm list eslint
If it exists, the command will return something like the following:
BASH├─┬ @typescript-eslint/[email protected]
│ ├─┬ @typescript-eslint/[email protected]
│ │ └── [email protected] deduped
│ ├─┬ @typescript-eslint/[email protected]
│ │ └── [email protected] deduped
│ └── [email protected] deduped
├─┬ @typescript-eslint/[email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
└─┬ [email protected]
└─┬ [email protected]
└── [email protected] deduped
If the package does not exist, the command will return something like the following:
BASH└── (empty)
Globally Installed NPM Packages
You can view the list of globally installed npm packages by running the npm list
command and specifying the --global
flag.
BASHnpm list --global
If you wish to view this list without the dependencies, you can run the command while specifying a depth of 0
.
BASHnpm list --global --depth=0
To check if a specific package is installed globally, you can run the command with the package name as the first argument.
BASHnpm list --global eslint
Conclusion
We've seen how to check where a npm package is installed, whether that package is installed locally or globally.
Hopefully, you've found this post helpful!
- How to Install Node on Windows, macOS and Linux
- Managing PHP Dependencies with Composer
- Getting Started with Express
- Create an RSS Reader in Node
- How to Serve Static Files with Nginx and Docker
- Build a Real-Time Chat App with Node, Express, and Socket.io
- Creating a Twitter bot with Node.js
- Building a Real-Time Note-Taking App with Vue and Firebase
- Getting Started with React
- Setting Up Stylus CSS Preprocessor
- Getting Started with Vuex: Managing State in Vue
- Using Axios to Pull Data from a REST API