How to Find and Delete All node_modules on Your Mac (2025 Guide)

Updated January 2025 -- 6 min read

If you work with Node.js, React, Vue, Next.js, or any npm-based project, your Mac is probably hiding gigabytes of node_modules folders. Each project gets its own copy of every dependency, and they accumulate fast.

5-30GB

Typical node_modules disk usage across all projects on a developer's Mac

This guide covers how to find them all, see how much space they use, and safely delete the ones you don't need.

Table of Contents

  1. Why node_modules Gets So Big
  2. Find All node_modules Folders
  3. Check Sizes Before Deleting
  4. Delete All node_modules at Once
  5. Delete Selectively (Safer)
  6. Clean npm/yarn/pnpm Caches
  7. GUI Tools (No Terminal Needed)
  8. Prevent Future Bloat

1. Why node_modules Gets So Big

A typical React project can have a node_modules folder of 200-500MB. Here's why:

Multiply that by 10-20 projects on your Mac, and you're looking at 5-30GB of node_modules.

2. Find All node_modules Folders

Basic Find

# Find all node_modules directories
find ~ -name "node_modules" -type d -prune 2>/dev/null
What does -prune do? It prevents find from descending into node_modules directories (which contain nested node_modules). Without it, the command would be extremely slow and return duplicates.

Search a Specific Directory

# Only search in your projects folder
find ~/Projects -name "node_modules" -type d -prune 2>/dev/null

# Or your Desktop/Documents
find ~/Documents -name "node_modules" -type d -prune 2>/dev/null

Count How Many You Have

# Count node_modules directories
find ~ -name "node_modules" -type d -prune 2>/dev/null | wc -l

3. Check Sizes Before Deleting

# Find all node_modules and show their sizes
find ~ -name "node_modules" -type d -prune -exec du -sh {} \; 2>/dev/null

Example output:

412M    /Users/you/Projects/old-react-app/node_modules
287M    /Users/you/Projects/portfolio-site/node_modules
1.2G    /Users/you/Projects/work/monorepo/node_modules
156M    /Users/you/Desktop/tutorial-project/node_modules
843M    /Users/you/Projects/nextjs-blog/node_modules

Sort by Size (Largest First)

# Show sizes sorted from largest to smallest
find ~ -name "node_modules" -type d -prune -exec du -sm {} \; 2>/dev/null | sort -rn

Get Total Size

# Total disk usage of ALL node_modules
find ~ -name "node_modules" -type d -prune -exec du -sm {} \; 2>/dev/null | awk '{total += $1} END {print total "MB"}'

4. Delete All node_modules at Once

Before you delete: This is safe for projects you're not actively working on. For active projects, you can always restore with npm install (or yarn / pnpm install). It just takes a minute.
# Delete ALL node_modules on your Mac
find ~ -name "node_modules" -type d -prune -exec rm -rf {} + 2>/dev/null

Delete Only in a Specific Directory

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

Delete Only "Old" node_modules (Not Modified Recently)

# Delete node_modules not modified in the last 30 days
find ~ -name "node_modules" -type d -prune -mtime +30 -exec rm -rf {} + 2>/dev/null

# Not modified in the last 90 days
find ~ -name "node_modules" -type d -prune -mtime +90 -exec rm -rf {} + 2>/dev/null
Pro tip: The 90-day filter is the sweet spot. If you haven't touched a project in 3 months, you probably don't need its node_modules. You can always npm install again.

5. Delete Selectively (Safer Approach)

If you want to review before deleting, use an interactive approach:

Using npkill (Interactive CLI)

# Install and run npkill
npx npkill

npkill shows all node_modules with their sizes and lets you select which ones to delete using arrow keys + space. It's the safest option.

Two-Step Approach (List, Then Delete)

# Step 1: List all node_modules to a file
find ~ -name "node_modules" -type d -prune -exec du -sh {} \; 2>/dev/null > ~/node_modules_list.txt

# Step 2: Review the file, then delete specific ones
cat ~/node_modules_list.txt  # review
rm -rf /path/to/specific/project/node_modules

6. Clean npm/yarn/pnpm Caches

Besides project-level node_modules, package managers maintain global caches:

Package Manager Cache Location Typical Size
npm ~/.npm/_cacache 500MB-5GB
yarn v1 ~/Library/Caches/Yarn 500MB-3GB
yarn v2+ .yarn/cache (per project) 100-500MB each
pnpm ~/Library/pnpm/store 500MB-5GB

Clean All Package Manager Caches

# npm cache
npm cache clean --force
# Check npm cache size
npm cache ls 2>/dev/null | wc -l

# yarn v1 cache
yarn cache clean

# pnpm store
pnpm store prune

# Check sizes
du -sh ~/.npm
du -sh ~/Library/Caches/Yarn 2>/dev/null
du -sh ~/Library/pnpm/store 2>/dev/null
Is it safe? Yes. Package manager caches just speed up installs. Cleaning them means npm install will download packages from the registry instead of using the cache. Slightly slower installs, but no functionality impact.

7. GUI Tools (No Terminal Needed)

If you'd rather not use the terminal, there are tools that provide a visual interface:

Tool Type Price node_modules Cleanup
ClearDisk macOS menu bar app Free (open source) Yes + 15 other dev caches
npkill CLI (interactive) Free (open source) Yes (node_modules only)
DaisyDisk macOS app $9.99 Manual (shows all files)
CleanMyMac macOS app $39-90/year Partial (system caches)

Clean node_modules + 15 Other Dev Caches

ClearDisk detects node_modules, npm cache, Xcode DerivedData, Docker, Homebrew, pip, CocoaPods, and more. One click to see sizes, one click to clean.

View on GitHub
# Install ClearDisk via Homebrew
brew tap bysiber/cleardisk && brew install --cask cleardisk

8. Prevent Future Bloat

Use pnpm Instead of npm

pnpm uses a global content-addressable store and creates hard links into project node_modules. This means packages are stored once on disk, regardless of how many projects use them.

# Install pnpm
npm install -g pnpm

# Use pnpm in your projects
pnpm install

Typical savings: 50-70% less disk usage compared to npm.

Set Up a Cleanup Schedule

Add this to your shell profile (~/.zshrc) as a quick alias:

# Add to ~/.zshrc
alias clean-nm='find ~/Projects -name "node_modules" -type d -prune -mtime +90 -exec rm -rf {} + 2>/dev/null && echo "Cleaned old node_modules!"'

Then just run clean-nm whenever you want to clean up.

Use .gitignore Properly

Make sure every project has node_modules/ in its .gitignore. This doesn't save disk space directly, but prevents node_modules from being tracked by git (which would double the storage with git objects).


Quick Reference

Task Command
Find all node_modules find ~ -name "node_modules" -type d -prune
Check total size find ~ -name "node_modules" -type d -prune -exec du -sm {} \; | awk '{t+=$1}END{print t"MB"}'
Delete all find ~ -name "node_modules" -type d -prune -exec rm -rf {} +
Delete old (90+ days) find ~ -name "node_modules" -type d -prune -mtime +90 -exec rm -rf {} +
Clean npm cache npm cache clean --force
Interactive cleanup npx npkill
GUI cleanup brew tap bysiber/cleardisk && brew install --cask cleardisk