npm list (or
npm ls which is my preferred shorthand) is a useful way to determine what npm packages are currently installed. The issue is, you get all their dependencies too (and their dependencies dependencies and their dependencies dependencies dependencies…). A bit frustrating, since this list is usually exceptionally long and no amount of nesting formatting can fully combat this.
Turns out there’s an easy way to combat this, although it’s not in the documentation for npm ls.
--depth=0 to the end of the command, it only draws out the top of the dependency tree. Happy days:
This even works for globally installed packages too, by adding the standard
I’m getting errors!
When I first tried this, I ended up with a bunch of nonsensical errors (e.g. “npm ERR! max depth reached” among others), although there was nothing really wrong.
You can combat this by adding
"$@" 2>/dev/null to the end. This essentially ignores the pointless errors by redirecting them to /dev/null. Nothing to see here, move along :)
The complete command
If you don’t want to type this out all the time (I certainly don’t), you can alias it up:
Then usage is as simple as: