npm list and Viewing Installed Packages
What you'll learn: How to inspect which packages are installed in your project and understand their dependency relationships using npm list.
Why Viewing Installed Packages Matters
After running npm install multiple times, your node_modules directory can become a black box. You might wonder: What's actually installed? Which version of a dependency am I using? Why is this obscure package even here?
The npm list command (also aliased as npm ls) answers these questions by showing you the complete dependency tree of your project.
Basic Usage
Run npm list in your project directory to see all installed packages and their dependencies:
npm list
This displays a tree structure showing each package, its version, and the packages it depends on—recursively, all the way down.
Think of it like a family tree: Your direct dependencies are the children you chose, but they bring their own children (sub-dependencies), grandchildren, and so on. npm list reveals the entire lineage.
Useful Options
Limit depth: Show only top-level dependencies:
npm list --depth=0
Check global packages:
npm list -g --depth=0
Find a specific package:
npm list lodash
This shows where lodash appears in your dependency tree and which packages depend on it.
JSON output for scripting:
npm list --json
What You'll See
The output shows package names, versions, and the tree structure. If a package appears multiple times at different depths, npm may deduplicate it or show where it's reused. Missing or problematic dependencies appear with error indicators.
Key Takeaway: npm list reveals the complete hierarchy of installed packages in your project, helping you understand dependencies, debug version conflicts, and audit what's actually in node_modules.