Updating Node and npm in Visual Studio

Visual Studio comes now with its own default Node.js plus npm on first install (if chosen) which saves you time on first set up, but unfortunately it doesn’t make it so easy to update due to its version of Node and npm being local. So how do you update them? First, a couple of useful tricks:

How do I check which global Node/Npm version I have installed?
Open a command line and write: “node -v” or “npm -v” depending on which one you want to check.

How do I check which Node/Npm version Visual Studio is using?
There’s a Visual Studio plugin called “Visual Studio Command Prompt” that can help you with this so you can open a command line and do as before.

If not, you can use the Task Runner Explorer adding a task like this and running it:
"check": "node -v && npm -v"

Another way using Window’s cmd is by going to your VS path: “C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\” (warning: depends on which VS version you’ve got) and proceeding as before (“node -v” or “npm -v”), this will tell you the local versions in that folder instead than the global ones.

Updating Node.js

First of, install the new global version in your computer as you normally would, go to the Node download page, take it and install. Check the version installed is the expected after you finish.

That said, that’s the global version, not necessarily the only version installed in your computer and as I just said, Visual Studio has its own, so to tell VS to use the global one instead here are a few options:

First, go to Tools > Options > Projects and Solutions > External Web Tools.

In here, VS has the different paths in which to look for its external tools, one of those is $(PATH), now if you add your global node.js installation path to the $PATH environment variable and then make sure that the $(PATH) is first on this list that should do it.

If that doesn’t work (VS restart probably required), you can try to add the path directly to the list, so click on “Add” and set “C:\Program Files\nodejs\” (usual path in which nodejs is installed). Again, restart and recheck.

If that’s not working then make sure that your nodejs is actually installed in that folder, if it looks like it is but still won’t work try uninstalling, check if it’s gone, sometimes due to permissions (maybe some other dev installed it with admin rights and you just can’t override it) or similar the installation doesn’t go as expected. Remove that folder manually. Install again and make sure on installing that the path where it’s installed is the expected one.

Updating NPM

Hopefully this won’t take that much, if you took Node.js from the website you probably already installed NPM with it, that is, the global one. You can double-check with “npm -v” at the command line. But to tell Visual Studio to use this global one you may need to do one of these:

Try steps for Upgrading Node.js, usually it also fixes NPM.

If not, go to the VS folder where the external tools are and force an installation of the latest NPM:
cd C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\
npm install npm@latest

That should upgrade Visual Studio’s NPM version to the latest.

If that still won’t work or you prefer another approach, try to add this task to your package.json: "update:npm": "npm install npm@latest -g". That will help giving the rest of the devs a tool to upgrade quite easily without having to remember where’s Visual Studio’s external tools path and with just a double click.

Leave a Reply

Close Bitnami banner
Bitnami