How to List NPM Packages and Dependencies

March 16, 2020

List Local Project NPM Packages and Dependencies

To print out locally installed NPM packages with their dependencies enter the following into your terminal:

npm list

This will print out a minimal version of your package-lock.json, which for some packages might be quite long and indented.

─┬ gatsby-plugin-sharp@2.4.3
│ ├── @babel/runtime@7.8.3 deduped
│ ├─┬ async@2.6.3
│ │ └── lodash@4.17.15 deduped
│ ├── bluebird@3.7.2 deduped
│ ├── fs-extra@8.1.0 deduped
│ ├── gatsby-core-utils@1.0.26 deduped
│ ├── got@8.3.2 deduped
│ ├─┬ imagemin@6.1.0
│ │ ├── file-type@10.11.0
│ │ ├─┬ globby@8.0.2
│ │ │ ├─┬ array-union@1.0.2
│ │ │ │ └── array-uniq@1.0.3

List Global NPM Packages and Dependencies

Adding -g to the end of npm list will print all global packages and their dependencies installed on your system instead of the local packages for your project.

npm list -g

List Only Top-Level Local Packages

If you only want to see the top-level packages, that is, the ones you directly installed and not their dependencies, then you use the --depth=0 option.

 npm list --depth=0

The number passed into --depth defines how many levels of dependencies you want to see printed out.

Codinhood@0.1.0 /Users/cody/projects/codinhood
├── @mdx-js/mdx@1.5.5
├── @mdx-js/react@1.5.5
├── @nivo/bar@0.61.1
├── @nivo/line@0.61.1
├── @nivo/pie@0.61.1
├── dayjs@1.8.20

This is essentially the same information as in your package.json, but minified and printed in your terminal.

List Only Top-Level Global Packages

Pass in the -g option along with the --depth=0.

npm list --depth=0 -g
├── jest@25.1.0
├── npm@6.13.4
├── serverless@1.64.0
└── serverless-cli@1.0.0