npm tricks part 1: Get list of globally installed packages

Alberto Schiabel
2 min readSep 28, 2016

--

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

This is especially true for Node.js/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 Node.js developer, who may not know every npm CLI trick.

So, this is it:

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:

Congratulations, you now know how to get a list of all the npm packages you have installed on your machine!

If this article helped you, consider subscribing to get my latest tutorials and thoughts about software engineering. If you like to experience Medium yourself, consider supporting me and thousands of other writers by signing up for a membership. It only costs $5 per month, and you get the chance of making money with your writing as well. You can cancel the membership anytime. By signing up with this link, you’ll support me directly, and it won’t cost you anything more. If you do so, you’ll encourage me to dedicate more time to knowledge sharing, so thank you a lot!

Let’s get in touch on Twitter, Github, or LinkedIn. My DMs are open, come to say hi 😊

--

--

Alberto Schiabel

Computer Scientist & Senior Software Engineer @ Prisma.io Interested in efficient algorithms, mathematical structures, and functional languages.