Working on lots of JavaScript projects? Your computer is probably stuffed with massive node_modules folders eating up your disk space. Let's look at how to clean them up easily with a tool called npkill.

Why node_modules Are a Pain

If you build websites or apps with JavaScript, you know the drill:

  • Every project gets its own huge node_modules folder
  • These folders are chunky - often 200MB to 500MB each
  • Old projects you forgot about still hog your disk space
  • Finding and deleting them by hand is boring and takes forever

What's npkill?

npkill is a simple tool that finds and helps you delete node_modules folders with just a few keystrokes.

How to Use npkill

Step 1: Run the Tool

The easiest way is to use npx, which lets you run it without installing anything:

npx npkill

This starts looking from where you are. To scan a specific folder:

npx npkill -d ~/projects

Step 2: Check Out What It Finds

npkill shows you a list with:

  • All the node_modules folders it found
  • How much space each one takes up
  • When you last used them
  • Easy controls to delete them

Step 3: Delete What You Don't Need

It's super easy to clean up:

  1. Use up/down arrows to move through the list
  2. Hit SPACE to mark a folder you want to delete
  3. Press d to delete the folder right away
  4. Press q to quit when you're done

Cool Tricks

npkill can do more than just find node_modules:

See biggest folders first

npx npkill --sort-by size

Skip folders you want to keep

npx npkill -e vendor,backup

Delete other folders too: Like dist or build folders

npx npkill -f dist,build

Tips for Better Cleanup

  1. Look at the dates - If you haven't touched a project in months, it's safe to delete
  2. Don't worry about mistakes - You can always run npm install later if you need those files again
  3. Do this every few months - Make it a habit when your disk gets full

For projects you're still using, try:

npm prune

This cleans up unused stuff without deleting everything

That's it!

With npkill, you can free up tons of space in just a few minutes. It's amazing how much disk space you can get back by cleaning up these folders!

Next time your computer slows down or you get a "disk full" message, give npkill a try - your computer will thank you!