If using Bash, just switch into the folder that has your package.json file and run the following:
for package in `ls node_modules`; do npm uninstall $package; done;
In the case of globally-installed packages, switch into your %appdata%/npm
folder (if on Windows) and run the same command.
EDIT: This command breaks with npm 3.3.6 (Node 5.0). I’m now using the following Bash command, which I’ve mapped to npm_uninstall_all in my .bashrc file:
npm uninstall `ls -1 node_modules | tr '/\n' ' '`
Added bonus? it’s way faster!
https://github.com/npm/npm/issues/10187