Node Modules Cleaner

Shell Script

A simple shell script which deletes all node_modules folders in the provided directory and all subdirectories.

Project Image

I have a base Macbook M1 Air with 256GB SSD and if you work Node.js ecosystem, you know how fast the node_modules folder can grow. After getting tired of manually deleting the node_modules folder as well as using the rm -rf node_modules command, I decided to write a simple shell script to automate this process.

Simple to operate, you run it like

./node_modules_cleaner.sh /path/to/your/projects-folder


Deleted: ./2024/proj1/node_modules
Space Freed: 316K

Deleted: ./2024/proj2/images/node_modules
Space Freed: 568K

Deleted: ./2024/proj3/audio/node_modules
Space Freed: 112M

Deleted: ./2024/proj4/app/node_modules
Space Freed: 341M

Deleted: ./2024/proj5/code-name/app/node_modules
Space Freed: 332M

Report generated at: node_modules_deletion_report.txt

It will delete all the node_modules folders in the provided directory and all subdirectories. It will also show you the total space saved by deleting the node_modules folders. Effecient and fast way to save disk space. But next time you run your old projects, you will have to run npm install again, so don't be alarmed with sudden errors.

You can find the script on my Github page, its open source so please feel free to modify and use it as per your needs.

Back To All Projects