List installed npm packages

Inspect local and global npm dependencies, expand the full tree when needed, and interpret missing, invalid, or extraneous packages.

Best practices
Illustration of files, modules, and their dependencies

Use npm ls --depth=0 for a project's top-level dependencies and npm ls --global --depth=0 for global packages associated with the active npm installation. list and ls are aliases.

npm ls --depth=0
npm ls --all
npm ls --global --depth=0
npm ls lodash

In current npm, an unqualified npm ls defaults to the root project's immediate dependencies. Use --all to request the full logical dependency tree. Older npm versions had different defaults, so an explicit depth makes a shared command clearer.

Read the dependency tree

Output such as express@4.19.2 identifies the installed package version; example version numbers are not upgrade recommendations. npm presents a logical dependency tree, which does not necessarily mirror the physical directory layout after hoisting or deduplication.

Pay attention to these annotations:

  • extraneous: a package is present but is not required by the dependency tree npm expects. This is broader than simply being absent from the root manifest.
  • UNMET DEPENDENCY or a missing dependency: an expected dependency is absent.
  • invalid: an installed version fails an applicable declared constraint.

An error exit status is not automatically a harmless peer-dependency warning. Read the reported problem, identify which package requires it, and fix the manifest or installation. A service starting successfully does not prove that all code paths and tooling will work.

Filter or export the result

npm ls --omit=dev --depth=0
npm outdated
npm ls --global --depth=0 > global-packages.txt
npm ls --global --depth=0 --json > global-packages.json

--omit=dev filters development dependencies from the listing; it does not uninstall them. npm outdated compares installed versions with available releases. A saved listing is useful as an inventory, but it is not itself an installation manifest.

Global packages depend on the active npm prefix. Switching Node versions through a version manager can therefore change the global list. Confirm node --version, npm --version, and npm prefix --global when results differ between terminals.

To trace a command, use command -v command-name in a POSIX shell or Get-Command command-name in PowerShell, then inspect its symlink or shim and the supplying package's bin field. The command name and package name need not be identical.

References

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting