Is there a command to remove all global npm modules? If not, what do you suggest?
Node.js – Command to remove all npm modules globally
node.jsnpm
Related Topic
- Node.js – Find the version of an installed npm package
- Javascript – How to completely uninstall Node.js, and reinstall from beginning (Mac OS X)
- Javascript – Sending command line arguments to npm script
- Node.js – How to uninstall npm modules in Node.js
- Node.js – What’s the difference between dependencies, devDependencies and peerDependencies in npm package.json file
- Node.js – the –save option for npm install
- Node.js – Do I commit the package-lock.json file created by npm 5
Best Answer
The following command removes all global npm modules. Note: this does not work on Windows. For a working Windows version, see Ollie Bennett's Answer.
Here is how it works:
npm ls -gp --depth=0
lists all global top level modules (see the cli documentation for ls)awk -F/ '/node_modules/ && !/\/npm$/ {print $NF}'
prints all modules that are not actually npm itself (does not end with/npm
)xargs npm -g rm
removes all modules globally that come over the previous pipe