How to List NPM Packages and Dependencies
March 16, 2019
List Local Project NPM Packages and Dependencies
To print out locally installed NPM packages with their dependencies enter the following into your terminal:
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.
1....2.─┬ gatsby-plugin-sharp@2.4.33.│ ├── @babel/runtime@7.8.3 deduped4.│ ├─┬ async@2.6.35.│ │ └── lodash@4.17.15 deduped6.│ ├── bluebird@3.7.2 deduped7.│ ├── fs-extra@8.1.0 deduped8.│ ├── gatsby-core-utils@1.0.26 deduped9.│ ├── got@8.3.2 deduped10.│ ├─┬ imagemin@6.1.011.│ │ ├── file-type@10.11.012.│ │ ├─┬ globby@8.0.213.│ │ │ ├─┬ array-union@1.0.214.│ │ │ │ └── array-uniq@1.0.315....
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.
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.
1.npm list --depth=0
The number passed into --depth
defines how many levels of dependencies you want to see printed out.
1....2.Codinhood@0.1.0 /Users/cody/projects/codinhood3.├── @mdx-js/mdx@1.5.54.├── @mdx-js/react@1.5.55.├── @nivo/bar@0.61.16.├── @nivo/line@0.61.17.├── @nivo/pie@0.61.18.├── dayjs@1.8.209....
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
.
1.npm list --depth=0 -g
1./Users/cody/.nvm/versions/node/v10.18.1/lib2.├── jest@25.1.03.├── npm@6.13.44.├── serverless@1.64.05.└── serverless-cli@1.0.0