Last Updated: September 09, 2019
·
32.29K
· Ionut-Cristian Florescu

npm list --depth=0

You probably know npm list will give you a comprehensive report of the installed npm modules. The problem is you'll get the entire dependency-tree, while you're mostly interested in the top-level modules.

I've recently come across this quick way to list just the top-level modules, so I thought I should share it with you here:

npm list --depth=0

...or, if you want to list the globally-installed modules:

npm list --depth=0 -g

npm list --depth=0

12 Responses
Add your response

Hi Ionut, this is very useful! Thanks for sharing!

over 1 year ago ·

neat!

over 1 year ago ·

really helpful!

over 1 year ago ·

Great, but why a photo? I mean... even girls from advertisement department in my company take screenshots.

Is it already viral to be a geek and take photos of a display? If yes, I'm in :)

over 1 year ago ·

Thank you all for reading and for your comments!

@nemoden - I don't have an advertising department, but when I'll do, I'll make sure to teach the girls some post-processing effects :-P. Actually it is a screenshot, with a perspective effect. Some people like it, some hate it, but in the end more people tend to notice/remember those :-)...

over 1 year ago ·

Hi,

This is very useful, thanks for sharing! I have a - most probably npm newby - issue and I hope you will be able to help me out.

When I run npm list -depth=0 in my project folder after the level 1 list I get the following error messages:

npm ERR! max depth reached: devtools-terminal[@]0.0.1, required by
undefined[@]undefined
npm ERR! max depth reached: grunt-cli[@]0.1.11, required by undefined[@]undefined
npm ERR! max depth reached: grunt-init[@]0.2.1, required by undefined[@]undefined
npm ERR! max depth reached: jsdoc[@]3.2.0-dev, required by undefined[@]undefined
npm ERR! max depth reached: npm[@]1.3.2, required by undefined[@]undefined
npm ERR! max depth reached: yuidocjs[@]0.3.45, required by undefined[@]undefined
npm ERR! not ok code 0

Sorry for the [@]-s, I couldn't figure out how to get Coderwall to render the @ without wrapping them up as anchors.

Could you help me figuring out why I am getting these?

Cheers!

over 1 year ago ·

@heartcode try npm list --depth=0 "$@" 2>/dev/null (essentially ignore pointless errors by redirecting them to /dev/null)

over 1 year ago ·

@leecrossley thanks for pointing that out!

It's also worth saying that one could add something like this in his .profile in order to save typing:

alias npml="npm list --depth=0 "$@" 2>/dev/null"

over 1 year ago ·

@icflorescu yep, great point

over 1 year ago ·

The --depth=0 parameter also works for npm outdated...

over 1 year ago ·

p r o t i p

nice one, the noise was bugging me!

over 1 year ago ·

Due to a bug in recent NPM versions, this doesn't work anymore, but you can use this hack instead.

over 1 year ago ·