Open In App

How to Get a List of Globally Installed NPM Packages in npm ?

Last Updated : 14 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Learning how to retrieve a list of globally installed NPM packages is essential for developers managing their Node.js environment. Utilizing npm, the Node Package Manager, enables users to efficiently manage packages across projects.

This article will guide you through getting access to global NPM packages, which will further help you to enhance your development efficiency.

Approach 1: Using ‘npm list’ command:

To get a list of globally installed npm packages, we can use npm list command in our terminal or command prompt. The npm list command is used to list installed npm packages.

  • -g flag indicates that you want to list globally installed packages.
  • –depth=0 option specifies the depth of the dependency tree to display. Setting it to 0 ensures that only the top-level packages are listed without their dependencies.

Syntax:

npm list -g --depth=0

Output:

Screenshot-2024-03-13-021138

displaying top-level packages

Approach 2: Using ‘npm ls’ command

The npm ls command is used to list installed packages. It shows a tree view of all installed packages in the current project, along with their dependencies.

  • -g flag indicates that you want to list globally installed packages.
  • –depth=1 option limits the depth of the dependency tree. In this case, --depth=1 limits the output to only the top-level packages and their direct dependencies.

Syntax:

npm ls -g --depth=1

Output

Screenshot-2024-03-13-021336

displaying top-level packages along with their immediate dependencies

Conclusion:

To conclude, obtaining a list of globally installed npm packages can be achieved through various approaches, each offering its unique level of detail and flexibility. By utilizing the NPM CLI commands like npm list -g –depth=0 and npm ls -g –depth=1, developers can gain insights into their global package setup, manage dependencies effectively, and streamline their workflow across projects.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads