Easily find and remove old and heavy node_modules/vendor folders with npkill

When working in web, you can be left with several lost node_modules (JS) and vendor (PHP) folders spread across your filesystem, unnecessarily taking up space.

To find these, I use the following command:

# List all node_modules (from current directory down) and their size
$ find . -name 'node_modules' -type d -prune -print | xargs du -chs

To remove all these, I use the following command:

# Remove all node_modules folders (from current directory down)
$ find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;

ℹ️ Replace node_modules with vendor to search for vendor folders (PHP)

But what if you only want to delete only a select few of those folders? Enter npkill, a tool that offers a UI to allow you to do just that in quick way:

This tool allows you to list any node_modules directories in your system, as well as the space they take up. You can then select which ones you want to erase to free up space. Yay!

You could install it globally, or leverage npx to run it immediately:

$ npx npkill

Using its --target option, you can use it to target vendor folders

$ npx npkill --target vendor

NPKILL – Easily find and remove old and heavy node_modules folders →

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Join the Conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.