Skip to content

Instantly share code, notes, and snippets.

@alokraj68
Forked from srdjanRakic/delete-node-modules.md
Created June 29, 2024 10:28
Show Gist options
  • Select an option

  • Save alokraj68/6b444dba17c249e9606e10c14ec7bf15 to your computer and use it in GitHub Desktop.

Select an option

Save alokraj68/6b444dba17c249e9606e10c14ec7bf15 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" rd /s /q "%d"

Powershell:

Get-ChildItem -Path "." -Include "node_modules" -Recurse -Directory | Remove-Item -Recurse -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment