Back to Blog
Tutorialnode_modulesdelete node_modulesnpmjavascriptdisk spacenode.js cleanup

How to Delete node_modules Safely: Reclaim 20-50GB of Disk Space

Learn the safest ways to delete node_modules folders without breaking your JavaScript projects. Find and remove old dependencies to free up disk space.

Cluttered Team
December 15, 2025
5 min read

The node_modules folder is notorious for consuming massive amounts of disk space. A single React project can have 300MB+ of dependencies, and across 20 projects, you're looking at 6GB or more.

Here's how to safely delete node_modules folders and reclaim that space.

How to Find All node_modules Folders

Using Terminal

# Find all node_modules directories
find ~ -name "node_modules" -type d -prune 2>/dev/null

# Show sizes
find ~ -name "node_modules" -type d -prune -exec du -sh {} \; 2>/dev/null | sort -hr

Check Total node_modules Size

# Total size of all node_modules
find ~ -name "node_modules" -type d -prune -exec du -sh {} \; 2>/dev/null | awk '{sum += $1} END {print sum "GB total"}'

How to Delete node_modules

Delete Single node_modules Folder

rm -rf /path/to/project/node_modules

Delete All node_modules Folders (Dangerous)

find ~ -name "node_modules" -type d -prune -exec rm -rf {} + 2>/dev/null

Warning: This deletes ALL node_modules folders, including active projects. You'll need to run npm install in every project.

Delete node_modules Older Than 30 Days

find ~ -name "node_modules" -type d -prune -mtime +30 -exec rm -rf {} + 2>/dev/null

Safer, but still doesn't check for uncommitted work.

The Problem with Manual Deletion

Manual deletion is risky because it doesn't consider:

  1. Active projects: You might delete dependencies for a project you're currently working on
  2. Uncommitted changes: The project might have work that depends on specific dependency versions
  3. Monorepos: Deleting root node_modules might break child packages
  4. Lock files: Without checking for package-lock.json, you might not restore exact versions

Safe node_modules Cleanup Checklist

Before deleting any node_modules folder, verify:

CheckWhy It Matters
Last modified dateOlder = safer to delete
Git statusNo uncommitted changes?
Has package-lock.json?Can restore exact versions
Is project archived?Might never need it again
Monorepo structure?Don't break workspaces

Skip the manual work

Cluttered finds and safely cleans all your node_modules automatically.

Download Free

Using npkill (Node.js Tool)

The npkill tool helps find and delete node_modules interactively:

npx npkill

Features:

  • Shows all node_modules with sizes
  • Interactive selection
  • Sorts by size or last modified

Limitations:

  • Doesn't check git status
  • No project activity analysis
  • Manual selection required

Cluttered provides intelligent node_modules cleanup:

  1. Scans entire drive for Node.js projects
  2. Checks git status to protect uncommitted work
  3. Analyzes activity using file modification times
  4. Shows clear indicators: Green (safe), Yellow (caution), Red (active)
  5. Deletes to Trash for easy recovery

Why Cluttered Is Safer

FeatureManual/npkillCluttered
Finds all node_modules
Shows sizes
Checks git status
Detects active projects
Trash-first deletion
Cleans other ecosystems

How Much Space Does node_modules Use?

Typical node_modules sizes by project type:

Project TypeAverage SizeWith Dev Dependencies
Simple website50-100MB100-200MB
React app200-400MB300-600MB
Next.js project300-500MB500-800MB
Monorepo500MB-2GB1-3GB
Electron app400-800MB600MB-1.2GB

Across 10-20 projects, this easily totals 5-15GB.

Reinstalling Dependencies After Cleanup

After deleting node_modules, reinstall when needed:

# Using npm
npm install

# Using yarn
yarn install

# Using pnpm
pnpm install

If you have a lock file (package-lock.json, yarn.lock, pnpm-lock.yaml), exact dependency versions are restored.

Preventing node_modules Bloat

1. Use pnpm Instead of npm

pnpm uses hard links to share packages between projects:

npm install -g pnpm
pnpm install

Can reduce total disk usage by 50-80%.

2. Regularly Clean Dormant Projects

Monthly cleanup of projects you haven't touched keeps things manageable.

3. Archive Old Projects

Before archiving to git or backup:

rm -rf node_modules
git add .
git commit -m "Archive project"

Never store node_modules in version control or backups.

4. Use .npmrc for Smaller Installs

# .npmrc
ignore-scripts=true
fund=false
audit=false

Reduces install time but not disk space.

Free Download

Stop Running Out of Disk Space

Cluttered finds and cleans node_modules, Rust targets, Xcode DerivedData, Docker cache, and more. Reclaim 50-100GB in minutes.

50-100GBtypical recovery
12+ecosystems
Safegit-aware cleanup
Download for MacmacOS 12.0+ · Apple Silicon & Intel

Frequently Asked Questions

Is it safe to delete node_modules?

Yes, if you have a package.json and package-lock.json. Running npm install restores everything.

Will deleting node_modules break my project?

Only temporarily. Your next npm install restores dependencies. The project won't run until then.

How do I delete node_modules on Windows?

# PowerShell
Remove-Item -Recurse -Force node_modules

# Or use npx
npx npkill

Should I commit node_modules to git?

No. Always add node_modules to .gitignore. It's reproducible from package-lock.json.

How often should I clean node_modules?

Monthly for most developers. More often if you work on many projects or have limited disk space.

What about global npm packages?

Those are in a different location and aren't affected by project cleanup:

npm list -g --depth=0
npm cache clean --force

Conclusion

Deleting node_modules is safe when done carefully. The key is checking for active projects and uncommitted work before mass deletion.

For safe, automated cleanup, use Cluttered. It handles node_modules alongside 11 other development ecosystems, protecting your active work while reclaiming disk space.

Download Cluttered and reclaim your disk space in minutes.