Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List node package dependencies without devDependencies

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,

  • Tools that do a static code analysis (madge, require-analyzer, module-grapher). But they don't do it recursively, visiting the required modules in the node_modules directory.
  • Tools that get the information from 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?

like image 502
Adam Schmideg Avatar asked Oct 14 '13 13:10

Adam Schmideg


People also ask

Does npm install devDependencies?

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.

How do I list npm packages?

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 .

What is the difference between devDependencies and dependencies in package json?

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.


1 Answers

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

like image 166
Cyberdelphos Avatar answered Sep 19 '22 17:09

Cyberdelphos