Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
2 views8 pages

Installing+and+Maintaining+NodeJS+(Windows)

Uploaded by

JTuretzky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Installing+and+Maintaining+NodeJS+(Windows)

Uploaded by

JTuretzky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Installing and maintaining Node.

js on
your Windows machine

Introduction

We have previously seen JavaScript code run in our browser, e.g. to provide logic to our
interactive application or manipulate the DOM. We have also been able to manually input
JavaScript commands and execute them through the browser's Dev Tools Console.

However, in order to be able to work with some JavaScript frameworks, like Jest for automated
testing or React for advanced frontend development, we need to be able to run JavaScript code
in our development environment independently of a web browser.

This is where Node.js comes in. Node.js is an open-source JavaScript runtime environment
which executes JavaScript code outside of a browser.

We need to install Node.js on our machine to use it in our local development environment. Also,
as different JS frameworks and their versions may require different versions of Node.js, we need
to be able to manage different versions of Node, i.e., install them and switch between them as
needed.

This walkthrough will guide you through the process of installing and maintaining Node.js on
your Windows machine.

Part 1: Install Volta

Some versions of operating systems may come with a version of Node.js already installed (the
“system” version). However, this is not sufficient - as stated above, we need the ability to install
multiple versions of Node and to switch between them as needed.

To achieve this, we are going to install and use Volta, a JavaScript tool manager.

1.​ Click on the Start Menu icon (or press the Windows key on your keyboard) and type
cmd, then click on Command Prompt.​

This will open the Command Prompt (CMD), which is Windows’ native command-line
interface.

2.​ In the CMD, enter the following command:


volta ls

If you get an output similar to this, it means that you already have Volta installed on your
system. In that case, you can skip the Volta installation and proceed to Part 2 of this
guide.
However, if you get the error “‘volta’ is not recognised as an internal or external
command, operable program or batch file”, please proceed with this installation.

3.​ In the CMD, enter the following command:


winget install Volta.Volta

Note: you may need to agree to the source agreement terms by typing Y and Enter.

4.​ Once the Volta installation has been completed, you can close the CMD window.

Part 2: Install Node.js

With Volta installed, we will install Node.js v22, the current long-time support (LTS) version.

Note: While there may be more up-to-date versions available (the official Node.js website
currently lists v23 as the most recent version), “LTS” indicates a trusted, stable and reliable
version which will be supported for a significant time in the future. This makes it suitable for our
purposes.

1.​ Open VS Code. You needn’t open any specific directory; just open the IDE.

From the top toolbar, open a terminal (Terminal > New Terminal).

2.​ In the VS Code terminal, enter the following command:


volta ls

If you get an output equivalent to v22.x.x (the values of .x.x depend on the most
up-to-date minor version of LTS v22), you have v22 already installed and activated. You
can skip the rest of this section and proceed to Part 3 of this guide.


However, if your output version is different from v22.x.x or you get the message “No
Node runtimes installed!”, please proceed with this installation.

3.​ In the terminal, enter the following command:


volta install node@22
4.​ Once the installation has been completed, in the terminal, enter the following command
again:
volta ls

You should now see an output equivalent to v22.x.x.

This means that Node.js v22 has been successfully installed and selected for use on
your machine. VS Code will now use this version whenever you open a VS Code
terminal or reopen a workspace with an already-opened terminal.

5.​ To verify that Node works and that it is the version you just installed, you can run the
following command:
node -v

Part 3: Install another version of Node.js

If you subsequently need to work on a different project that, for compatibility reasons, requires a
different version of Node than the one you originally installed and activated, you need to be able
to install and switch to that second version. If you then need to revisit your original project, you
also need to be able to switch back to the original/previous version of Node.

Luckily, once Volta is installed on your computer as described in Part 1, installing additional
versions of Node and switching between them is really simple and straightforward.

In this Part, we will install Node.js v16 as the second version and set it to active. To do this, we
will use Volta again.
In the VS Code terminal, enter
volta install node@16

If you now enter volta ls in the terminal, you should get the following output:

And running node -v - to verify that Node works - should return the same version of Node:

Using volta install node@<version> in this manner - where <version> is always the
major version number (e.g. the “16” in “16.20.2”) - you can install as many available major
versions of Node.js on your machine as you want.

Part 4: Switching between versions of Node.js

To switch back to the previously installed v22 now, simply enter the following command in the
terminal:
volta install node@22
You can use volta ls to check that v22 is now the active version again.

Using volta install node@<version> in this manner - where <version> is always the
major version number (e.g. the “22” in “22.13.0”) - you can switch to any available major
version of Node.js on your machine.

As you can see from Parts 3 and 4, Volta makes no real distinction between installing a version
and switching to a version - both actions are performed with the same volta install
node@<version> command, and the Node version invoked with the command becomes active
immediately. The only difference is that running the command for a version that had previously
been already installed will simply activate it, whereas running the command on a version that
has never been installed will first download and install it, and then activate it.

As a consequence, the active Node version will always be the one that was last invoked with
volta install node@<version>. To avoid the need to keep constant track of which
version you installed last, you can always check the active version by entering volta ls or
node -v in any VS Code terminal. It is recommended to check the active version of
Node.js in this manner whenever you open (or reopen) a workspace in VS Code to work
on a Node.js project. This will help you avoid inadvertent incompatibility issues between
Node.js and your project’s dependencies.

You might also like