DEV Community

Kiran (AK) Adapa
Kiran (AK) Adapa

Posted on • Edited on

Javascript projects and optimize space on your laptop

(last updated Apr 5, 2025)

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

Use npkill

This tool allows you to easily identify and remove unnecessary node_modules folders.

   npx npkill
Enter fullscreen mode Exit fullscreen mode

This command will go through all the projects/directories and lists the "Releasable Space" in GB. It lists all node_modules directories and their sizes, allowing you to delete them selectively. You may use the up/down arrow on your keyboard to select a project and just hit the 'space bar' on the select that project's node_modules be cleaned up. All the folders that are deleted are marked and the "Space saved" in GB is updated.

See the screenshot here:

npkill screenshot

Use a shell script:

Create a script to automatically delete node_modules folders in inactive projects.

   #!/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)