npm list Explained

What npm list does, with an example.

Published November 11, 2026

npm list (npm ls) prints the tree of installed packages. Use it to see versions, find duplicates and understand why a package is installed.

How it works

npm ls <pkg> shows every path where a package appears. --depth limits how deep the tree goes.

npm explain <pkg> shows why it is installed.

Try it

npm ls --depth=0
app@1.0.0
├── express@4.19.2
└── jest@29.7.0

Practical examples

Top level only

npm ls --depth=0

Who needs a package

npm ls lodash
npm explain lodash

Global packages

npm ls -g --depth=0

JSON output

npm ls --json --depth=0

Common mistakes

  • Reading the whole tree when --depth=0 would do.
  • Ignoring UNMET DEPENDENCY warnings.
  • Confusing ls with outdated.

Key takeaways

  • npm list (npm ls) prints the tree of installed packages.
  • Run npm help <command> for every option.
  • Commit package-lock.json.

FAQ

Find duplicates?

npm ls <pkg> or npm dedupe.

Does this work with yarn or pnpm?

They have equivalents with similar commands.

More JavaScript articles