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!
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
I got 14
, it means I've 12
dependency.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With