Guides

How to find and delete old node_modules folders on a Mac

node_modules folders in projects you've moved on from can add up to many gigabytes. Here's how to find them, how much they take, and how to remove them safely.

Last checked 29 September 2026

Every JavaScript project keeps its own copy of its dependencies in node_modules, often a few hundred megabytes each. Projects you finished months ago keep theirs too. Removing them is safe: npm install brings them back if you return to a project.

Find them, with their sizes

In Terminal, from the folder where you keep your code (for example ~/Developer):

find . -name node_modules -type d -prune -exec du -sh {} + | sort -h

-prune stops the search going inside each node_modules, which would otherwise list thousands of nested ones and take far longer. The largest appear last.

Only the old ones

To list node_modules whose project’s package.json hasn’t changed in 90 days:

find . -name package.json -not -path "*/node_modules/*" -mtime +90 -execdir test -d node_modules ; -print

A package.json that hasn’t changed is a good sign a project is idle, though not proof: check the list before removing anything.

Remove them

Emptying the Trash is what returns the space to your disk.

Stop them piling up

Freeing space matters beyond tidiness: macOS needs free disk space to swap, and a nearly full disk is one of the most common reasons a Mac feels slow.