Skip to content

Instantly share code, notes, and snippets.

@yyx990803 yyx990803/nl.sh
Last active Oct 25, 2019

Embed
What would you like to do?
npm list only top level modules.
alias ng="npm list -g --depth=0 2>/dev/null"
alias nl="npm list --depth=0 2>/dev/null"
@Nilegfx

This comment has been minimized.

Copy link

Nilegfx commented Jan 6, 2016

Thanks for this one, may I ask, what does the "/dev/null" do?

@danqing

This comment has been minimized.

Copy link

danqing commented Jan 14, 2016

@refactorized

This comment has been minimized.

Copy link

refactorized commented Jun 12, 2016

perfect nl is exactly the alias I had in mind

@jlafitte

This comment has been minimized.

Copy link

jlafitte commented Sep 21, 2016

Just be careful, nl is also a "line numbering filter" utility. Not sure if you have it on your system, but it could cause problems if another script needs it. I'm using nlg nll.

@rondinif

This comment has been minimized.

Copy link

rondinif commented Dec 28, 2016

These aliases are awesome but I just warn about possible conflict that may arise with https://github.com/angular/angular-cli [ng]((https://cli.angular.io/reference.pdf) and the ng alias.

@attluh

This comment has been minimized.

Copy link

attluh commented Jul 16, 2017

This is awesome, exactly what I was looking for!

@awadev

This comment has been minimized.

Copy link

awadev commented Jan 2, 2018

Thanks, based on this info I wrote a small bash script, usage can be
npl , npl 0 , npl 1 , npl 2 g, npl g , npl -h etc.
where 0,1,.. is the level and g is global, of course. Hope it helps someone.

(Don't forget to put it in a folder in your path and to chmod +x it.)
http://awadev.com/npl

@ackalker

This comment has been minimized.

Copy link

ackalker commented May 6, 2018

Note that options like --depth 0 can be set in npm's config as well.

So to make npm ls work more like *nix ls -l i.e. show only the top-level modules, you can run:

npm config set depth 0

Of course, you can always override this config setting from the command line, so to restore the original behaviour, i.e. make npm ls work more like *nix ls -lR, you can run:

npm ls -g --depth 9999

Note that setting depth in config also applies to npm la, npm ll, npm ls --long, etc., so no need to define shell aliases for any of those either.

@hinell

This comment has been minimized.

Copy link

hinell commented Apr 11, 2019

Check this out npm ls -ps

@richworx

This comment has been minimized.

Copy link

richworx commented Aug 8, 2019

This doesn't seem to work for node installed by nvm. I have to use --depth=1 to see the installed packages. Does anyone have a solution that works for both (or an easy way to detect whether the running npm is from nvm or not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.