Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get number of npm modules installed except dev dependencies

Is there an NPM CLI command I can use to get the number of NPM Modules installed in my package, excluding those that are only Dev Dependencies? npm ls shows all of the packages, but it doesn't say how many or which are Dev Dependencies and which aren't. Thanks!

like image 458
Ben Gubler Avatar asked May 17 '18 18:05

Ben Gubler


2 Answers

Try this

  npm ls --only=prod --depth=0 | wc -l

Now subtract by 2 whatever you get. ( -1 is for last line and another -1 is for first line where npm ls shows the directory.)

(Use git-bash if you're using Windows.)

Demo

enter image description here

I got 14, it means I've 12 dependency.

like image 124
Ritwick Dey Avatar answered Oct 18 '22 12:10

Ritwick Dey


You can use:

npm ls --only=dev
npm ls --only=prod

For this purpose, you can also do

npm ls --dev

or

npm ls --prod

Pipe it out to grep to count:

npm ls --depth=0 --dev | grep "\-\-" -c
like image 22
Terry Lennox Avatar answered Oct 18 '22 10:10

Terry Lennox