DEV Community

SaKKo
SaKKo

Posted on • Edited on

Anyone can show me how to safely delete node_modules to clear up harddisk space?

UPDATED:

For anyone who found this post,
I found a package called npkill

https://github.com/voidcosmos/npkill

--END--

Hi all

I use a Mac and it comes with 512GB SSD. There are so many things in stalled and my SSD is low on space.

I would say docker take the most space in my laptop. But I found out that cleaning up node_modules from older projects could help.

First, please let me give you some background.

  1. I run a software development team where there are more than 100 projects in both ruby and nodejs in my computer. Which I organise like this.
    • ~/_workspace root folder for all code. _ is to make it easy to access.
    • ~/_workspace/customer_1_name/project_1_name
    • ~/_workspace/customer_1_name/project_2_name
    • ~/_workspace/customer_2_name/project_1_name
    • I usually name folder with underscore case.
  2. I use NVM and .nvmrc in my projects.
    • There are so many node_modules folders from yarn and npm i which is taking too much space on my laptop.
  3. I use RVM and .ruby-version and .ruby-gemset in my projects.
    • Rails use yarn and some project has node_modules which is also taking too much space.
  4. There are more than 100 folders to clean up and that's for me only. My team need to do this as well.

I need help I safely delete node_modules folders. Or if anyone face the same problem, please share your experience.

Thank you so much.

Top comments (2)

Collapse
 
rdhox profile image
rdhox

There is no big problem that I know of to delete the node_modules folder of a project. A simple yarn or npm install will recreate it.

I use this line of code to get rid of my node_modules folders in the root of all my project's folders (before a backup for example):

find . -name "node_modules" -exec rm -rf '{}' +

More info here: stackoverflow.com/questions/429505...

Collapse
 
markpieszak profile image
Mark Pieszak

I wrote up an article here about how to achieve it on Mac/Windows actually!
trilon.io/blog/how-to-delete-all-n...