Note: This is just improving on the accepted answer, please use the accepted answer first.
If you are so bored then keep reading.
Basically, this command should work fine for 99% of cases
find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +
I notice that deleting files via the command line is longer than deleting a folder via Finder (when deleting from Finder it moves that folder to ~/.Trash directory).
So if you want to move node_modules to ~/.Trash folder then you can try
find . -name 'node_modules' -type d -prune -exec sh -c 'mv -f "$1" "$(dirname "$1")/$(basename $(dirname "$1"))_$(basename "$1")" && mv "$(dirname "$1")/$(basename $(dirname "$1"))_$(basename "$1")" ~/.Trash/' sh {} \;
as you notice it consist of 2 parts.
find . -name 'node_modules' -type d -prune
find all node_module dirs
-exec sh -c 'mv -f "$1" "$(dirname "$1")/$(basename $(dirname "$1"))_$(basename "$1")" && mv "$(dirname "$1")/$(basename $(dirname "$1"))_$(basename "$1")" ~/.Trash/' sh {} \;
rename node_module by prefixing it with it's parent folder name and move it to Trash
Before I had
~/Development/angular-projects
┣ project1
┣ project2
┗ project3
After running command
~/.Trash
┣ ~project1_node_modules
┣ ~project2_node_modules
┗ ~project3_node_modules
Then make sure to empty trash

Or Turn On empty trash feature
