node.js uninstall not - Command to remove all npm modules globally?




8 Answers

For those using Windows, the easiest way to remove all globally installed npm packages is to delete the contents of:

C:\Users\username\AppData\Roaming\npm

You can get here quickly by typing %appdata% (either in explorer, run prompt, or start menu).

working ubuntu list

Is there a command to remove all global npm modules? If not, what do you suggest?




sudo npm list -g --depth=0. | awk -F ' ' '{print $2}' | awk -F '@' '{print $1}'  | sudo xargs npm remove -g

worked for me

  • sudo npm list -g --depth=0. lists all top level installed
  • awk -F ' ' '{print $2}' gets rid of ├──
  • awk -F '@' '{print $1}' gets the part before '@'
  • sudo xargs npm remove -g removes the package globally



For those using Powershell:

npm -gp ls --depth=0 | ForEach-Object { Get-Item $_ } | Where { $_.Name -ne 'npm' } | ForEach-Object { npm rm -g $_.Name }

To clear the cache:

npm cache clear



If you have jq installed, you can go even without grep/awk/sed:

npm ls -g --json --depth=0 |
  jq -r '.dependencies|keys-["npm"]|join("\n")' |
  xargs npm rm -g

On Debian and derived you can install jq with:

sudo apt-get install jq



in windows use "C:\Users\username\AppData\Roaming" path and manually remove npm folder




Well if you are on windows, and want to remove/uninstall all node_modules then you need to do following steps.

  1. Go to windows command prompt
  2. Navigate to node_modules directory (Not inside node_modules folder)
  3. Type below command and give it for 1-2 minutes it will uninstall all directories inside node_module

     rmdir /s /q node_modules
    

Hope this will help some one on windows




npm ls -gp | awk -F/ '/node_modules/&&!/node_modules.*node_modules/&&!/npm/{print $NF}' | xargs npm rm -g



It's as simple as: rm -rf ~/.npm






Related


Tags

node.js   npm