How to List NPM Packages and Dependencies

March 16, 2019

node

List Local Project NPM Packages and Dependencies

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

bash
1.npm list

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

bash
1....
2.─┬ gatsby-plugin-sharp@2.4.3
3.│ ├── @babel/runtime@7.8.3 deduped
4.│ ├─┬ async@2.6.3
5.│ │ └── lodash@4.17.15 deduped
6.│ ├── bluebird@3.7.2 deduped
7.│ ├── fs-extra@8.1.0 deduped
8.│ ├── gatsby-core-utils@1.0.26 deduped
9.│ ├── got@8.3.2 deduped
10.│ ├─┬ imagemin@6.1.0
11.│ │ ├── file-type@10.11.0
12.│ │ ├─┬ globby@8.0.2
13.│ │ │ ├─┬ array-union@1.0.2
14.│ │ │ │ └── array-uniq@1.0.3
15....

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.

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

bash
1.npm list --depth=0

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

bash
1....
2.Codinhood@0.1.0 /Users/cody/projects/codinhood
3.├── @mdx-js/mdx@1.5.5
4.├── @mdx-js/react@1.5.5
5.├── @nivo/bar@0.61.1
6.├── @nivo/line@0.61.1
7.├── @nivo/pie@0.61.1
8.├── dayjs@1.8.20
9....

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.

bash
1.npm list --depth=0 -g
bash
1./Users/cody/.nvm/versions/node/v10.18.1/lib
2.├── jest@25.1.0
3.├── npm@6.13.4
4.├── serverless@1.64.0
5.└── serverless-cli@1.0.0