Updating your Node.js environment

I have used to use Windows Update and Visual Studio Extensions and Updates feature. Now the problem is that keeping your Node.js environment up-to-date is not possible using those tools.

There are couple package managers available for Windows, but there are no “native” for example PowerShell command that could be executed. I don’t like to use a tool for just single task.

Node.js

You can see Node.js version number when you start Node.Js Command Prompt

UpdateNodeJs_NodeJsVersionNumber

So far the easiest way to update your Node.js to download installer from Node.js web site from https://nodejs.org/en/download/. Note that there are two versions available LTS and Current. LTS stands for Long Term Support. Now I’m currently running the latest version of Node.js so I don’t need to update it.

UpdateNodeJs_DownloadNodeJsLTS

If you select LTS (it’s selected by default), you can see that Current version is v.4.4.7 with npm version 2.15.8.

UpdateNodeJs_DownloadNodeJsCurrent

If you select Current, you can see that Current version number has changed to v.6.3.1 with npm version 3.10.3.

Npm

If I have the latest version of Node.js, it doesn’t mean that I have the latest version of NPM. I found really excellent script that will update NPM for you with couple commands. https://www.npmjs.com/package/npm-windows-upgrade. It will show the current version of the NPM installed to your system. It also installs “any” NPM version you want so you can downgrade if the latest version would turn out to be buggy.

Open PowerShell as Administrator

UpdateNodeJs_StartPowerShell

Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force

UpdateNodeJs_PSSetExecutionPolicy

npm install --global --production npm-windows-upgrade

UpdateNodeJs_PSInstallNpmWindowsUpgrade

npm-windows-upgrade

UpdateNodeJs_PSNpmWindowsUpgrade

Now we can close PowerShell and start Node.js Command Prompt to verify that installation was successful.

npm version

UpdateNodeJs_CmdNpmVersion

Possible error messages

You can get few error message while executing npm-windows-upgrade.

The first one “Scripts cannot executed on this system.” comes if you haven’t changed execution policy.

UpdateNodeJs_ErrorScripts

The another one “NPM cannot be upgraded without administrative rights. To run PowerShell as Administrator, right-click PowerShell and select ‘Run as Administrator’.” comes if you try to execute npm-windows-upgrade with non-administrative mode.

UpdateNodeJs_ErrorRights

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.