DEV Community

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

Posted on

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

Top comments (0)