Delete all node_modules subfolders

3.2k Views Asked by At

I'm doing a HDD upgrade, and while trying to backup my NodeJS projects i realize that all node_modules subfolders have over 1 milion files.

So i'm looking for a way to remove all the node_modules subfolders and all their contents.

The projects are located in :

C:/Node/App1/node_modules/..
C:/Node/App2/node_modules/..
C:/Node/App3/node_modules/..
etc..

My OS is Windows 10, but i can try either Windows or Linux commands because i'm using cmder, and it accepts both types of commands.

2

There are 2 best solutions below

0
On BEST ANSWER

I tested this command in various situations and it seems to work fine.

for /d /r . %d in (node_modules) do @if exist "%d" rd /s/q "%d"

I'm not sure how it works, it's an adapted solution from Here, if you need more details.

0
On

For Linux:

cd Node
find . -maxdepth 2 -name node_modules -type d -exec rm -rf {} +