First: is node_modules safe to delete?
Usually, yes. node_modules is fully regenerated by npm install (or yarn / pnpm install) from your package.json and lockfile. What you actually pay is reinstall time and network access the next time you open the project. The exceptions worth knowing:
- Projects with locally patched packages (e.g.
patch-package) — the patches reapply on install, but only if they were committed. - Very old projects whose dependencies no longer resolve or build on current tooling — deleting node_modules there can mean the project never installs again.
- Anything currently running — stop dev servers before deleting.
Option 1: a find one-liner
List every node_modules folder under your projects directory and how big each one is:
find ~/Projects -name node_modules -type d -prune -exec du -sh {} +Then delete them all:
find ~/Projects -name node_modules -type d -prune -exec rm -rf {} +The risk: rm -rf is immediate and unrecoverable — there is no Trash, no undo. The command doesn't know whether a folder belongs to a real project, whether the project still installs, or whether you meant to include that path. One mistyped directory and the command happily deletes it.
Option 2: npkill
npkill is a popular free CLI that lists node_modules folders and lets you delete them interactively:
npx npkillIt's a solid tool for exactly this one job. Its limits: it only knows about node_modules (not build outputs, Python caches, or Xcode data), deletion is permanent rather than via Trash, and it doesn't check Git status or project context before deleting.
Option 3: RepoSweep
RepoSweep is a macOS app built for this cleanup across all your project types, with safety as the core feature:
- Finds node_modules plus
.next,dist,build,coverage,__pycache__, Xcode DerivedData, and dozens of other regenerable artifacts across 14 ecosystems. - Verifies the project behind every match and checks Git status — anything Git tracks is never offered.
- Explains how each item regenerates before you decide.
- Only moves items to macOS Trash — every deletion can be undone with Finder's Put Back.
Scanning is free and unlimited, so you can see exactly how much space is recoverable before paying anything. Download RepoSweep for macOS 14+ or see pricing — a one-time $12, no subscription.
Which should you use?
If you only ever accumulate node_modules and are comfortable with permanent deletion, npkill does the job. If your disk is filled by a mix of JavaScript, Python, Xcode, and other build artifacts — or you want deletions to be reversible — that's the case RepoSweep was built for.