inspect
npm list
Prints the installed dependency tree of the current project (or globally). Aliases: `ls`, `la`, `ll`.
npm list [<pkg>] [--depth=<n>] [--global] [--json] Common flags
| Flag | Purpose |
|---|---|
| --depth <n> | Tree depth to display (0 = only top-level) |
| --global (-g) | List global installs instead of the local project |
| --json | Machine-readable JSON tree |
| --all (-a) | Show the full dependency tree |
| --prod / --dev | Filter to production or development dependencies |
Examples
npm ls --depth=0 List only top-level project dependencies
npm ls -g --depth=0 List globally-installed packages
npm ls react Show every place react resolves to in the tree
Gotcha
Since npm 7, `npm ls` exits with a non-zero code when the tree is invalid (extraneous or missing peers) — this can break shell pipelines. Pair with `npm why` when you need to understand a nested version.
Related commands
npm outdated
Compares installed versions against the registry and reports which packages have a newer version available in current/wanted/latest columns. `wanted` respects your semver range, `latest` is the newest published.
npm why (explain)
Prints the dependency chain(s) that caused a specific package (or version) to be installed. Alias: `why`; invaluable for tracking down duplicate copies or unexpected transitive deps.
npm view (info)
Fetches package metadata straight from the registry — versions, maintainers, dist-tags, dependencies, and more. Aliases: `info`, `show`, `v`.