I counted the folders named node_modules on my Mac. There were 110, in project folders alone.
Together they held 17 GB. One of them was 6.3 GB on its own. Storage settings never showed any of it as one thing.
Every one of those folders comes back with a single install command. Before you delete one, check that nobody is still working on its project.
node_modules is where npm, Yarn, pnpm, and Bun put a project’s packages, and every project gets its own copy. Find them with find, sort them by size, and delete the folders for projects nobody is working on. They come back with one npm install the next time you need the project, and the lock file brings back the same versions. npm’s caches live in ~/.npm, and npm cache clean --force doesn’t touch the npx part of it.
Why there are so many of them
A JavaScript project doesn’t share packages with other projects. Each one downloads its own copy into its own node_modules folder. That’s often hundreds of megabytes, and sometimes gigabytes once a build tool and its plugins are in. Clone a few side projects, try a few templates, and they add up.
They don’t show up as one big folder anywhere. They’re spread across every project I’ve ever installed on the Mac.
Find them, biggest last
This lists every node_modules folder under your projects folder with its size, smallest first, so the biggest end up at the bottom:
find ~/dev -type d -name node_modules -prune -exec du -shx {} + | sort -h
Change ~/dev to wherever you keep projects. The -prune stops find from opening the node_modules folders nested inside other node_modules folders, which would count the same space twice. The -x keeps du on one disk.
To see the total:
find ~/dev -type d -name node_modules -prune -exec du -skx {} + | awk '{s+=$1} END {printf "%.1f GB\n", s/1048576}'
On my Mac, ~/dev alone printed 10.6 GB. Adding the projects kept in other folders brought it to 17 GB, so run it on every folder where you keep code.
Check whether anyone still uses the project
Finder’s date on a project folder doesn’t tell you when the project last changed. A folder’s date only changes when something is added or removed right inside it. Edit a file two folders down, and the project folder keeps its old date. So a project someone worked on yesterday can look like nobody has opened it in a year.
This checks the files instead. It prints the first file in the project that changed in the last 90 days. It skips node_modules, .git, and Finder’s .DS_Store files, since those change without anyone working on the project:
find ~/dev/old-project \( -name node_modules -o -name .git -o -name .DS_Store \) -prune -o -type f -mtime -90 -print -quit
If it prints a file, someone changed that project in the last 90 days. If it prints nothing, nobody did. When I tried it on October 28, it printed a package.json on the first project I picked, so that one stayed.
90 days is the same line Diskling uses to decide which project folders to tick for you. Raise the number if you want to be more careful.
Delete node_modules for the projects you’re done with
Delete only the project’s node_modules folder, not the project:
rm -rf ~/dev/old-project/node_modules
rm -rf skips the Trash, so read the path twice before you press Return. Your code, package.json, and lock file stay where they are.
When you come back to the project, npm install (or yarn, pnpm install, bun install) rebuilds the folder. The lock file is what makes that safe. npm’s package-lock.json docs say it describes the exact tree that was installed, so the next install can make an identical one. A project with no lock file gets the newest versions its package.json allows, which may not be what it had before.
For the exact versions, npm ci installs straight from the lock file and never changes it. It also removes an existing node_modules folder before it starts, so you don’t need to delete it first.
If you’d rather pick from a list, npkill shows every node_modules folder with its size and lets you delete them one by one:
npx npkill
With more than a handful to go through, I’d use npkill over typing rm -rf paths, because you see each folder’s size before anything goes and there’s no path to mistype.
pnpm keeps one shared copy of each package in its own store and links projects to it. Deleting a project’s node_modules frees less than its size suggests. Run pnpm store prune afterward to remove packages no project uses anymore.
Don’t forget the caches
Package managers keep a cache of everything they’ve downloaded, outside your projects. My Mac had 48 more node_modules folders inside ~/.npm, from packages run once with npx. They live in ~/.npm/_npx, 3.0 GB on mine, and npx downloads them again when you need them.
npm cache clean --force empties npm’s download cache, and only that. npm’s cache docs put that cache in a folder called _cacache, and they say npm never removes cache data by itself, so it keeps growing. The npx folder isn’t part of it.
npm 11, the version on this Mac, has separate commands for the npx folder. The first lists what’s in there, one line per entry with the package names. The second clears all of it, and npm won’t do that without --force:
npm cache npx ls
npm cache npx rm --force
Yarn has yarn cache clean, and pnpm has pnpm store prune. Whatever these remove comes back on the next install. That install is slower, because everything downloads again.
What I’d do: make the list with the first find command and run the 90-day check on the biggest few. Then pick the old ones by hand, because only you know which project you plan to open next.
What Diskling shows here
Diskling finds the build folders in your projects, like node_modules, vendor, and target, and counts one only when the project file that makes it sits beside it, such as package.json. It groups them by project with the date each one last changed, and ticks only projects untouched for 90 days. It never touches files Git tracks, and what you remove goes to the Trash, so Undo brings it back.
Start with the first find command and read the last three lines of its list. On my Mac, one folder in those lines held 6.3 of the 17 GB, so that’s where I’d start and leave the rest for later.
Questions people ask
Is it safe to delete node_modules?
Yes. It only holds packages a project downloaded. Your code, package.json, and lock file stay, and npm install or npm ci puts the folder back.
Will deleting node_modules break my project?
Not if the project has a lock file, because the next install uses the same versions. Without one, npm picks the newest versions package.json allows, which can differ from what you had.
Does npm cache clean delete node_modules?
No. npm cache clean --force only empties npm’s download cache in ~/.npm/_cacache. Your projects’ node_modules folders stay, and so does the npx cache in ~/.npm/_npx.
Where is the npm cache on a Mac?
In ~/.npm, a hidden folder in your home folder. Downloads are in _cacache, and packages you ran with npx are in _npx.

Comments
No comments yet. Tried this on your Mac? Tell me how it went.