Every JavaScript project gets its own node_modules folder. Each one can be a few hundred megabytes, sometimes more, and they stay around long after you stop working on the project. If you have a folder full of old tutorials, side projects and client work, the total can be surprising.
I cleared mine last month and got back a lot more than I expected. Here is how.
Why node_modules gets so big
npm and Yarn (in its classic mode) copy every dependency into each project separately. Two projects using the same version of React still each keep their own copy. pnpm handles this better by sharing a single store, but most older projects were not set up with it.
The upside is that node_modules is always safe to delete. Running npm install (or yarn, or pnpm install) rebuilds it from package.json and the lock file.
Finding them from Terminal
From your projects folder, this lists every node_modules folder with its size:
find . -name node_modules -type d -prune -exec du -sh {} +
The -prune part stops find from looking inside node_modules for more node_modules, which would take forever.
To delete all of them under the current folder:
find . -name node_modules -type d -prune -exec rm -rf {} +
That one does not ask for confirmation and does not go to the Trash. Run the listing command first and make sure you are in the right folder.
There is also a tool called npkill that you can run with npx. It shows a list of node_modules folders and lets you pick which to delete.
Finding them visually
I like seeing the whole picture first. A disk space analyzer for Mac shows your projects folder as blocks, and the node_modules folders stand out right away.
DissectMac has a storage map that does this. It also has a node_modules filter that lists every copy across the drive, and you can send them to the Trash from inside the app. That Trash step is the part I like compared with the Terminal command. If I delete a folder from a project I am still using, I can put it back without reinstalling.
Other places dependencies pile up
- npm cache. Run npm cache verify to tidy it, or npm cache clean --force if you want it gone.
- Yarn cache. Run yarn cache clean.
- pnpm store. Run pnpm store prune.
- Global packages. Run npm ls -g --depth=0 to see what you installed globally and remove what you do not use.
Other developer folders to check
If you are cleaning up a dev machine, node_modules is only one part. These usually take even more:
- Docker.raw is huge on my Mac
- Xcode DerivedData cleanup
- Local AI models eating Mac storage
A habit that helps
When you finish with a project, delete its node_modules before archiving the folder. The code stays, the dependencies can come back any time, and your backups get faster too. For the rest of the machine, my how to clean my Mac checklist covers the non developer side.

Top comments (0)