DEV Community

Cover image for remove all the node_modules directories from machine | Free Up Space
HasOne
HasOne

Posted on

4

remove all the node_modules directories from machine | Free Up Space

we as developer have hundred of project in the machine, but have you've ever wondered how much space node_modules takes on single project and what happens when you're running out of free space. this will help you to make some free space safely.

List All the node_modules/ folders

before removing let's show all the node_modules directories and its memory. cause the removing process is irrevisable so we need to make sure. first cd into a specific directory where most of the projects are:

LINX/MACOS

$ cd Dev/
$ find . -name "node_modules" -type d -prune | xargs du -chs
Enter fullscreen mode Exit fullscreen mode

Screenshot 2021-10-02 at 06.41.02

WINDOW

$ cd Dev 
$ FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" echo %d"
Enter fullscreen mode Exit fullscreen mode

Remove all the node_modules/

now let's remove all the node_modules directories from all the projects. make sure that you're inside a directory where you're comfortable removing all the node_modules cause this action is irereversable:

LINUX

$ cd Dev
$ find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
Enter fullscreen mode Exit fullscreen mode

WINDOW

$ cd Dev 
$ FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" rm -rf "%d"
Enter fullscreen mode Exit fullscreen mode

Final Word

a single node_modules took about 400MB - 90MB in my cases and total space it took around 10gigabyte - 15gigabyte. it will help you to free up some space in your machine if you have limited SSD, but if you've removed from all the directories, you have to install it again for the project you're working on, keep this in mind.

I hope you enjoyed this article and learnt something valuable, thank you all and stay blessed!

Me: https://ericgit.me

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay