How to check if an npm package installed globally or locally
In this tutorial, we are going to learn about how to check whether an npm package (or module) is installed globally or locally using the npm list
command.
Checking globally installed packages
To check for all globally installed packages and its dependencies, run the npm list
command followed by the -g
flag.
npm list -g
This above command prints the all globally installed packages in tree view.
To view the globally installed packages, without their dependencies use:
npm list -g --depth=0
You can also check if a specific package is installed globally or not using the npm list -g
followed by package name.
npm list -g express
Checking locally installed packages
To check for all locally installed packages and their dependencies, navigate to the project folder in your terminal and run the npm list
command.
npm list
To view the locally installed packages, without their dependencies use:
npm list --depth=0
You can also check if a specific package is installed locally or not using the npm list
command followed by package name.
npm list react