guide
How to find every node_modules folder and how big it is
Quick answer
List them, biggest last:
find ~/Projects -name node_modules -type d -prune -print0 | xargs -0 du -sh | sort -hThe total: find ~/Projects -name node_modules -type d -prune -print0 | xargs -0 du -sch | tail -1. Finding is instant; measuring takes a while because du has to visit every file.The command, piece by piece
find ~/Projects -name node_modules -type dfinds folders named node_modules.-prunestops at each match instead of walking into it, so you get one line per project and it finishes in about a second.-print0 | xargs -0keeps folder names with spaces intact.du -shmeasures each folder;sort -horders human-readable sizes like 900M and 2.4G correctly.
find ~/Projects -name node_modules -type d -prune -print0 | xargs -0 du -sh | sort -h
How long it takes
On the Mac Sweep was built on, find listed every matching folder in 0.8 seconds, but du took 1 minute 54 seconds to measure them, because node_modules folders hold hundreds of thousands of small files. Measuring several folders at once is much faster: Sweep does the same measurement across all cores in about 18 seconds.
The React Native trap: node_modules that aren't
If you have React Native projects, the list can be inflated. Android's native build cache, android/app/.cxx, mirrors your project's paths, so it contains folders literally named node_modules deep inside, like .cxx/Debug/…/CMakeFiles/…/node_modules. On our Mac, 140 of the 245 "node_modules" that find reported were these mirrors, inflating the list more than twofold. Exclude them:
find ~/Projects -name .cxx -prune -o -name node_modules -type d -prune -print
The .cxx folder itself is safe to delete (Gradle recreates it) and can be hundreds of megabytes.
Other folders worth measuring
node_modules is rarely the only one. On the same Mac: Gradle build + .cxx 34.8 GB, CocoaPods Pods 23.1 GB, Flutter build 18.8 GB, .next 18.5 GB, .dart_tool 8.6 GB.
find ~/Projects \( -name node_modules -o -name Pods -o -name .next -o -name .dart_tool \) -type d -prune -print0 | xargs -0 du -sh | sort -h
Careful with generic names like build, dist or vendor: in some projects they are source. A website template's assets/vendor, for example, is your code.
Questions
How do I see the total size of all node_modules?
find ~/Projects -name node_modules -type d -prune -print0 | xargs -0 du -sch | tail -1 prints one total line.
Why is du so slow?
It has to look at every file to add up sizes, and node_modules folders contain hundreds of thousands of small files. find is fast because -prune never goes inside them.
Does du count hard links twice?
Within one du run, a hard-linked file is counted once. pnpm hard-links node_modules into a shared store, so a folder can look bigger than the space deleting it would free.
Can I search my whole home folder?
You can, but it is slower and finds things in Library you should not touch. Point it at the folders your projects live in.