I have done this a ton of times but generally using pnpm and I always forget it. Having just got a new laptop I wanted to move my old code repos from one machine to the other but need to delete (the huge amount) of node_modules I have accumulated.
When Googling the command I found a great blog post that explains it well and outputs the paths and node_modules sizes before you delete them.
First up the command to list them all and the sizes:
find . -name "node_modules" -type d -prune -print | xargs du -chs
Once you are happy you want to delete them all you can use the following command:
find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;
Source: Trilon blog