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 lsOutput:
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.1Listing 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=0Output:
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.2You can also list only the production dependency packages in a tree view like this.
npm ls --prodor development dependencies:
npm ls --devYou 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

