Recently when starting to work on a new project, I thought It'd be a good idea to update my Node.js and NPM versions. At that time my Node.js and NPM versions were 16.13.2
and 8.6.0
respectively. Although I have updated these in the past, this time I found out that there is a more efficient and quick way of doing this. In this article, I'll be sharing some ways that I found to be very helpful to me to update and manage Node.js versions. So without further ado, let's dive.
My usual way of updating Node.js
So before we get into how to update in a more efficient way, let me share with you, the first and usual way I do this.
- Since I use Windows, the first thing I do is, go to Control Panel and uninstall the Node.js application from there.
- Then I go to the Node.js website and download the latest stable version of node.
- After downloading, I go through a boring series of
Next
button clicks in the installation wizard. - Then I open up the Command Prompt and type
node --version
to see if it has been installed correctly. - After I confirm that it works, I continue my normal workflow to build the project.
This is my usual way of updating Node.js. Now, NPM comes alongside Node.js, so I do not have to install it separately and when I use my "usual" way of updating Node.js, it automatically comes with the latest version of NPM. But the thing about NPM is that it gets updates more frequently than Node.js. In this case, I use a simple command, npm update -g
to update just the NPM version to the latest.
So what's wrong with this? Well, there's actually nothing wrong about it, instead, it's just not an efficient way of doing it. And also like I said, firstly I uninstall the current version and then install the latest version I want. This would be a bummer if I wanted to have multiple versions of Node.js for different projects. And as a matter of fact, I do, so every time I switch to a different project, there's a high chance that I used a different Node.js version in that project, which my current version does not support. I tried to install different Node.js versions on my computer, but I had no luck in making them work. I don't know if it is something to do with Node.js, Windows or just me :p.
A better way of updating and managing Node.js
So I started looking for an alternative and efficient way of updating Node.js. This is when I came across different articles and sources where most of them recommended nvm
- The Node Version Manager tool. This is a tool that easily allows you to quickly install and use different versions of Node.js via the command line. The thing about this tool is that it supports only POSIX-compliant shells like sh, dash, ksh, zsh, bash, which works particularly on Unix, macOS Windows WSL, so again I tried this way, but still no luck. I couldn't get the installation of this to quite work (maybe because it supports only Windows WSL). Then I started looking for a version of nvm
for Windows and I found nvm-windows
, a tool similar but not identical to nvm
, but for Windows. And it comes with an installer to easily download it onto Windows. So this is the tool I currently use for managing different Node.js versions. I haven't faced any bugs so far, and it has been a very useful tool that I regret to have not found it earlier.
Main takeaway
If you are someone who installs/updates Node.js using my usual method, I highly recommend you switch to a more efficient one, you'll save a lot of time. I did some research and gathered the following ways:
nvm
- A Node Version Management tool.n
- Also a Node Version Management tool. (less popular thannvm
)nvm-windows
- A similar tool tonvm
but not identical (for Windows).
The above tools are very highly rated and liked by developers when it comes to managing Node.js versions. By using one of these tools, you are not only able to update Node.js, but also to install multiple versions and easily switch between these versions easily from your command line with just a single short command.
For example, in nvm-windows
, I can use:
nvm install <version>
- to install a specific versionnvm list
- to list out all versions installednvm use <version>
- to use/switch between different versions.Note:- I found that you need to open your command line as an Administrator in Windows to perform the
nvm use
command.
Thanks for reading!
And that's it for this article. If you enjoyed reading this article and found it to be useful, consider liking and sharing it with others. If you have a different method of updating Node.js, let me know in the comments down below.
And as always, if you have any questions or feedback let me know in the comments down below and follow me on Twitter for more updates on my journey, tips and tricks about programming. Ta-ta 👋