Skip to content

Instantly share code, notes, and snippets.

@srdjanRakic
Last active June 29, 2024 10:28
Show Gist options
  • Save srdjanRakic/ef6478f7e2b29be82e6d841e98b2dd70 to your computer and use it in GitHub Desktop.
Save srdjanRakic/ef6478f7e2b29be82e6d841e98b2dd70 to your computer and use it in GitHub Desktop.
How to Delete ALL node_modules folders on your machine

List all node_modules found in a Directory:

First, let's take a look at ALL the node_modules we have in a directory, before we actually start deleting them!

Mac / Linux:

cd documents
find . -name "node_modules" -type d -prune -print | xargs du -chs

--- Example output ---
1.0G ./Github/big-project/node_modules
225M ./Github/Trilon.io/node_modules
482M ./Github/Some_Demo/node_modules

1.7G total

Windows:

cd documents
FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" echo %d"

Delete all node_modules found in a Directory:

Mac / Linux:

  $ cd documents
  $ find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;

Windows:

$ cd documents
$ FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" rm -rf "%d"

Powershell:

Get-ChildItem -Path "." -Include "node_modules" -Recurse -Directory | Remove-Item -Recurse -Force
@alokraj68
Copy link

FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" rd /s /q "%d"

this will delete folders silently in command prompt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment