Is there a command to remove all global npm modules? If not, what do you suggest?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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=0lists 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 rmremoves all modules globally that come over the previous pipe