Skip to main content

Clean up old projects

· One min read
Daniel Ruf

Sometimes folders like node_modules consume too much space and then a small cleanup may be needed.

Until we migrate to pnpm which deduplicates files and drastically saves disk space, this is my approach to how I free up some disk space in projects with Node.js:

find . -name "node_modules" -type d -exec du -sh {} + | sort -hr

This command recursively searches for all folders named node_modules, calculates their size, and then sorts them in ascending order. All in human-readable form.

There is also the package npkill, which can be run via npx npkill. This gives you an interactive selection of the relevant paths.

For Composer-based projects, you can run find . -name "vendor" -type d -exec du -sh {} + | sort -hr and check the results. In my case an old project consumed around 1.5 GB of disk space.