How to list NPM packages installed globally on your computer

Learn how to list NPM packages installed globally

Posted on July 23, 2021


NPM packages can be installed globally using the -g or --global flag so that the package can be used from the console.

To list all NPM packages that you’ve installed globally on your system, you can use the npm list -g command from your console:

npm list -g
# or
npm list --global

# for npm v6 and below
npm list -g --depth=0

Here’s an example of running the command on my console:

$ npm list -g
/Users/nsebhastian/.nvm/versions/node/v16.3.0/lib
├── @vue/cli@4.5.13
├── express@4.17.1
├── gulp-cli@2.3.0
├── http-server@0.12.3
├── npm@7.15.1
├── purgecss@4.0.3
└── rimraf@3.0.2

As you can see from the output above, the npm list command will also print out the location where the packages are installed.

Sometimes, you may see other developers recommending you to use --depth=0 config when running npm list command:

npm list -g --depth=0

The --depth=0 config is used to hide the dependencies of each installed package from the output. Since NPM version 7, the npm list command already hides the dependencies by default.

If you want to display the dependencies of your installed packages in version 7, then you need to use the --all config:

npm list -g --all

Additionally, if you install an NPM package in a custom location using the --prefix config, then you need to add the same --prefix config when running the the npm list command.

For example, suppose you install the express package in a custom location as follows:

npm install express --prefix /Users/nsebhastian/Desktop/test/nodeWs

Add the same --prefix command when calling npm list command:

$ npm list --prefix /Users/nsebhastian/Desktop/test/nodeWs
node-websocket-example@1.0.0 /Users/nsebhastian/Desktop/test/nodeWs
├── express@4.17.1
├── react@17.0.2
└── ws@7.5.1

Conclusion

To display a list of installed packages in NPM version 7, use the npm list -g command.

For version 6 and below, use the npm list -g --depth=0 command.

By default, NPM version 6 and below will print out the dependencies, which you can hide by using the --depth=0 command.

Starting from NPM version 7, the dependencies of each installed package will be hidden from the output by default.

If you’re using NPM v7, use the --all config to display the dependencies of installed packages (or use --depth=1 to display only top-level dependencies. Your choice)

When you install packages in a custom location using the --prefix config, then you need to add the same config when you call the npm list command.

Related articles:

Level up your programming skills

I'm sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.