node_modules folders are rebuildable: delete one and npm install (or pnpm install, or yarn) puts it back. That makes them the easiest disk space to reclaim on a developer machine. Here’s how to do it for every project at once, in three steps: list, measure, then delete.
Step 1: list them
Always look before you delete. Run these from the folder that holds your projects, not from / or your whole home folder on the first try.
-prune matters: it stops find from descending into a node_modules it has already found, so you get only the top-level folder for each project, and the command finishes far sooner.
Step 2: measure them
The biggest folders are usually old projects using heavy frameworks, or monorepos. That’s where to start.
Step 3: delete them
On Windows, also read why deleting node_modules is slow on Windows.
What’s safe to delete, and what isn’t
The blind find … rm -rf approach treats every folder named node_modules the same. Most are safe, but not every folder with a familiar name is generated, and not every generated folder is worth deleting.
A few things to watch for:
- Global installs. Tools installed with
npm install -glive in anode_modulesfolder too (for example under/usr/local/libor your Node version manager’s directory). Deleting it breaks those CLIs. Don’t run the command from/or your Node install folder. - Apps that ship a
node_modules. Some desktop apps and extensions bundle anode_modulesfolder that they need to run. Keep the search inside your projects folder. - Locally patched dependencies. If you edited a file inside
node_modules(or use a patching tool that hasn’t been committed), it’s gone after deletion. - Lockfiles stay. Don’t delete
package-lock.json,pnpm-lock.yamloryarn.lock. They’re tiny and they’re what makes the reinstall reproducible.
Doing it with a review step
This is the workflow Gigaflush is built around. It looks for node_modules only when there’s a package.json next to it, lists each one with its size, preselects nothing, and shows the full paths plus how to rebuild before anything is removed. It also covers Rust target, Flutter build and .dart_tool, Python tool caches, Swift .build, and Gradle and Maven output, so one scan finds everything.
Getting a project back
When you return to a project, reinstall from the lockfile:
npm ci # npm, exact versions from package-lock.json
pnpm install # pnpm
yarn install # Yarn
That’s it: the folder you deleted was always a cache of what those commands produce.