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

← All npm commands · npm vs pnpm vs Yarn · Fix Node OOM