Skip to Content

Devin Clark

Quick Tip: Useful Npm Package Listing

We've all had to suffer through npm ls and it's endless trees of dependencies but there is a better way!

That way is the --depth flag. That's right, it was as easy as npm ls --depth=0. Now you can see the packages you actually installed.

That was easy... too easy... If you ran that command you probably noticed a bunch of these little buggers at the bottom of the output.

npm ERR! max depth reached: express@3.5.2, required by my-project@0.4.18

Let's fix this. Start by running sudo nano ~/.profile. If you would rather use vi for this, type alias vi='nano'; sudo vi ~/.profile. Then, add this line to the file, save, and reload ~/.profile by running source ~/.profile.

alias "npmls0"="npm ls --depth=0 2>/dev/null"

The key to this is 2>/dev/null. All it does it eat the errors.

Now you can just run npmls0 and see your npm packages and their associated versions.

Source

Photo of Devin Clark
Devin Clark
Principal Software Engineer, Oracle
You Might Also Like