When NPM is broken on Windows
So, have you ever broke your NPM or Node? I did, and it was a pain to fix it. But here is how a fully cleaned install of NPM and Node on Windows looks like.
Uninstalling NPM and Node
Uninstall node from Programs & Features with the uninstaller.
Remove all the shortcuts like on task managers/ desktop etc
Remove all the folder given below
C:\Program Files (x86)\Nodejs
C:\Program Files\Nodejs
C:\Users\{User}\AppData\Roaming\npm (or %appdata%\npm)
C:\Users\{User}\AppData\Roaming\npm-cache (or %appdata%\npm-cache)
C:\Users\{User}\.npmrc (and possibly check for that without the . prefix too)
Remove from the environment variable via checking Path value
Open your command prompt try to run below command
where node
If it will show directories then delete all the directories
Reboot your system
Go to the node js side download or directly install the node from there
Installing NPM and Node
After you have uninstalled NPM and Node, you can install them again from NodeJS Official Website. Here, we are choosing the 64-bit version of the Node.js installer.
The LTS (Long-term Support) version is the recommended version for most users. It’s the version that is most stable and most widely used. The Current version is the most recent version of Node.js. It will have the newest features, but it might also have some bugs (you probably already know that).
The installer will download to your default download location. Once the download is complete, open the installer to begin the installation process.
You will get a welcome message on the screen. Click on the Next button to continue.
- Choose the desired path where you want to install Node.js.
- By clicking on the Next button, you will get a custom page setup on the screen. Make sure you choose npm package manager, not the default of Node.js runtime. This way, we can install Node and NPM simultaneously.
The following features will be installed by default:
- Node.js runtime
- Npm package manager
- Online documentation shortcuts
- Add to Path
By now the setup is ready to install. Click on the Install button to start the installation process.
If you have a doubt whether you have installed everything correctly or not, let’s verify it with “Command Prompt”.
node -v
and then check for npm
npm -v
And that’s it! With these steps, I turned a frustrating situation into a smooth and successful reinstallation of NPM and Node on my Windows machine.