Skip to content

Instantly share code, notes, and snippets.

@devillom
Created October 12, 2019 01:17
Show Gist options
  • Save devillom/8e0b549194fb472dc4fbafa7af55bca2 to your computer and use it in GitHub Desktop.
Save devillom/8e0b549194fb472dc4fbafa7af55bca2 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!
NOTE: Make sure you cd into a specific directory where most of your projects are. ie: documents or documents/github.
Mac / Linux:
This command will print out each folder, and even show us how much space the folder is occupying !
$ 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"
This list will give you a good idea of just the sheer amount of projects you have installed on your machine!
Delete all node_modules found in a Directory:
NOTE: Use caution here, and make sure that you are in a directory where you're comfortable removing all the instances of node_modules, run the script above to see a full list of them all before deleting.
This script is actually very similar to the one above, but we're going to be utilizing rm -rf to completely delete them.
WARNING: This process is irreversible!
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 Users:
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