Free space by deleting node_modules


Did you know you can free disk space by deleting node_modules?

To check the disk usage of your current working directory:

du -sh .

To find all directories (in your working directory) that matches the name node_modules:

find . -type d -name 'node_modules'

Execute recursive remove on all matches:

find . -type d -name 'node_modules' -exec rm -rf {} \;

Display the disk usage of your current working directory:

du -sh .

Example

Here’s an example of how to delete node_modules of a project bootstrapped by Create React App.

Create app:

npx create-react-app my-react-app

Check disk usage:

du -sh
248M  .

Delete node_modules:

find . -type d -name node_modules -exec rm -rf {} \;

Check disk usage:

du -sh
924K  .


Please support this site and join our Discord!