by Sai gowtham

How to list installed packages in Npm

In this tutorial, we are going to learn about how to list (view) the npm installed packages and its dependencies in a tree structure in the terminal.

Listing installed packages and dependencies

The npm ls command helps us to list (view) all versions of installed packages and their dependencies in the terminal.

npm ls

Output:

node-app@1.0.0 /Users/saigowtham/Desktop/node-app
├─┬ cors@2.8.5
│ ├── object-assign@4.1.1
│ └── vary@1.1.2
├── date-fns@2.15.0
├── dotenv@8.2.0
├── esm@3.2.25
├─┬ express@4.17.1
│ ├─┬ accepts@1.3.7
│ │ ├─┬ mime-types@2.1.27
│ │ │ └── mime-db@1.44.0
│ │ └── negotiator@0.6.2
│ ├── array-flatten@1.1.1

Listing installed packages but not dependencies

If you want to list only the installed packages without their dependencies, you need to pass the — depth=0 flag at the end of the npm ls command.

npm ls — depth=0

Output:

node-app@1.0.0 /Users/saigowtham/Desktop/node-app
├── cors@2.8.5
├── date-fns@2.15.0
├── dotenv@8.2.0
├── esm@3.2.25
├── express@4.17.1
├── express-rate-limit@5.1.3
└── rimraf@3.0.2

You can also list only the production dependency packages in a tree view like this.

npm ls --prod

or development dependencies:

npm ls --dev

You can also list the globally installed packages instead of in the current project by adding a -g flag to the npm ls command.

npm ls -g

# without dependencies

npm ls -g --depth=0

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
45,614 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
130,921 students enrolled
21 hours of video content
View Course