I'd like to get a list of all external dependencies of my node.js project that is modules required by my project and modules required by those modules. I tried two approaches,
node_modules
directory.package.json
. Well, not really tools, it means a plain npm ls
invocations only.The problem with the second approach is that is lists packages specified as devDependencies
, too. I realized I'd be happy to run npm ls --no-dev
or something like that. I tried npm ls --production
, but it doesn't make any difference. Any idea how I can achieve it?
When you (or another user) run npm install , npm will download dependencies and devDependencies that are listed in package. json that meet the semantic version requirements listed for each.
Use the npm list to show the installed packages in the current project as a dependency tree. Use npm list --depth=n to show the dependency tree with a specified depth. Use npm list --prod to show packages in the dependencies . Use npm list --dev to show packages in the devDependencies .
A dependency is a library that a project needs to function effectively. DevDependencies are the packages a developer needs during development. A peer dependency specifies that our package is compatible with a particular version of an npm package.
I had to use:
npm ls --prod
and to only show the first level of the tree:
npm ls --prod --depth=0
Here are the docs: https://docs.npmjs.com/cli/ls
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