How to use‘npm ls’ command in NPM

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

displaying top-level packages along with their immediate dependencies

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

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.

Table of Content

  • Using ‘npm list’ command
  • Using ‘npm ls’ command

Similar Reads

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....

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....

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....