DEV Community

Kiran (AK) Adapa
Kiran (AK) Adapa

Posted on

Javascript projects and optimize space on your laptop

If you are a javascript/nodejs developer, then changes are node_modules from your projects is going out of control.

Get your space back on your macbook or to better manage space consumed by "node_modules" for various Node.js and React.js applications, you can try one of two things given here:

Remove Unused node_modules

  1. Use npkill: This tool allows you to easily identify and remove unnecessary node_modules folders[4][25].
   npx npkill
Enter fullscreen mode Exit fullscreen mode

This command will list all node_modules directories and their sizes, allowing you to delete them selectively.

  1. Use a shell script: Create a script to automatically delete node_modules folders in inactive projects[11][28].
   #!/bin/bash
   find . -name "node_modules" -type d -mtime +30 -exec rm -rf {} +
Enter fullscreen mode Exit fullscreen mode

This script removes node_modules folders that haven't been modified in the last 30 days.

Top comments (0)