How to remove all globally installed npm modules
In this tutorial, we are going to learn about how to remove all globally installed npm modules from your system.
Removing specific npm module
To remove a specific npm module, you need to run npm uninstall -g
command followed by the module name.
Here is an example that removes the globally installed react
module.
npm uninstall -g react
Removing all npm modules
To remove all npm modules from your system, you can use the following command.
npm ls -gp --depth=0 | awk -F/ '/node_modules/ && !/\/npm$/ {print $NF}' | xargs npm -g rm
This above command scans all globally installed npm modules and removes each module by running npm -g rm
Note: This above command works on Linux, macOS and anywhere you are using Linux environment.
For windows, you need to open the following folder and delete all contents present in that folder.
C:\Users\username\AppData\Roaming\npm
or you can open that folder by searching the following path inside the explorer.
%appdata%/npm