Back to Blog
Tutorialsnode.jsnpmjavascriptdisk space

How to Clean node_modules Without Breaking Your Projects

A practical guide to safely reclaiming disk space from JavaScript dependencies without losing important work.

Cluttered Team
December 15, 2024
2 min read

JavaScript's node_modules folder is notorious for its size. A typical React project can easily have 200+ MB of dependencies, and that's for a relatively simple app.

If you're working on multiple projects, those folders add up fast. Here's how to clean them safely.

The Manual Approach

You could manually find and delete old node_modules folders:

# Find all node_modules folders
find ~ -name "node_modules" -type d -prune

# Delete them (be careful!)
find ~ -name "node_modules" -type d -prune -exec rm -rf {} +

Warning: This approach is risky. You might delete dependencies for a project you're actively working on.

The Smart Approach

Before deleting any node_modules folder, you should ask:

  1. When was this project last modified? If it was 6 months ago, it's probably safe to clean.
  2. Is this a git repository? If so, are there uncommitted changes?
  3. Can you easily reinstall? Is there a package-lock.json or yarn.lock?

What Cluttered Does Differently

Cluttered automates this entire process:

  1. Scans your entire drive for Node.js projects
  2. Checks git status to ensure no uncommitted work
  3. Analyzes activity using file modification times
  4. Shows clear indicators - green (safe), yellow (caution), red (active)
  5. Deletes to Trash so you can recover if needed

Real-World Results

A typical developer machine has:

  • 10-20 Node.js projects
  • Average node_modules size: 300 MB
  • Total recoverable: 3-6 GB (or more)

And the best part? Running npm install in any project will restore it instantly.

Tips for Keeping Things Clean

  1. Use a single global cache: npm and yarn both support global caching
  2. Delete old projects: If you haven't touched it in a year, archive and delete it
  3. Use Cluttered regularly: Set up automatic cleaning for inactive projects

Conclusion

You don't need to let node_modules folders consume your disk. With the right approach, you can keep your machine clean while staying productive.

Download Cluttered and reclaim your disk space in minutes.