Monday, June 1, 2020

Get list of globally installed packages

Quick question: does everybody of you folks know the exact amount of globally installed npm packages in your workstation? Probably not.

This is especially true for NodeJS/npm newbies, who often try the most popular packages installing them globally, without even defining them in their package.json files; however, this may be useful even for more advanced NodeJS developer, who may not know every npm CLI trick.

So, this is it: npm list -g --depth 0

Let’s break this line down a little bit, shall we?

  • npm: the Node package manager command line tool
  • list -g: display a tree of every package found in the user’s folders (without the -g option it only shows the current directory’s packages)
  • — depth 0 / — depth=0: avoid including every package’s dependencies in the tree view

Here’s a sample result: