🎯 Introduction

JavaScript is a powerful language, often run in the browser to manipulate the DOM and add interactivity. However, when working with advanced JavaScript frameworks like React or tools like Jest for automated testing, it’s necessary to run JavaScript outside of the browser. This is where Node.js comes in.

Node.js is an open-source JavaScript runtime that allows you to run JavaScript code in your development environment, independent of a browser. To take advantage of Node.js in your local environment and manage different versions of it (as required by various frameworks), you need to install Node.js and use a tool to manage multiple versions.

In this post, we’ll walk through the process of installing and maintaining Node.js on your Windows machine, using Volta, a tool for managing JavaScript versions.


πŸ”§ Part 1: Install Volta

Before we install Node.js, we need to install Volta, a tool manager for JavaScript. Volta allows us to manage different versions of Node.js, making it easy to switch between versions when necessary.

Step 1: Open the Command Prompt

  1. Click on the Start Menu (or press the Windows key) and type cmd.
  2. Select Command Prompt from the search results to open it.

Step 2: Check if Volta is Already Installed

In the Command Prompt, enter the following command:

volta ls
  • If Volta is already installed, you’ll see an output listing the available tools.
  • If you see the error β€˜volta’ is not recognised..., proceed to the next step to install Volta.

Step 3: Install Volta

  1. In the Command Prompt, enter the following command to install Volta:
    winget install Volta.Volta

    You may need to agree to the source agreement terms by typing Y and pressing Enter.

  2. Once the installation is complete, you can close the Command Prompt.

πŸ“¦ Part 2: Install Node.js

With Volta installed, let’s now install Node.js. We will install Node.js v22, which is the LTS (Long Term Support) version. LTS versions are stable and reliable, making them ideal for development purposes.

Step 1: Open Visual Studio Code (VS Code)

You don’t need to open any specific directory. Just open VS Code and launch a new terminal by selecting Terminal > New Terminal from the top toolbar.

Step 2: Verify if Node.js v22 is Already Installed

In the VS Code terminal, enter:

volta ls
  • If Node.js v22 is already installed, you’ll see something like v22.x.x.
  • If Node.js isn’t installed, proceed with the next steps.

Step 3: Install Node.js v22

In the VS Code terminal, enter the following command to install Node.js v22:

volta install node@22

Step 4: Verify Installation

After the installation is complete, enter the following command to confirm that Node.js v22 is active:

volta ls

You should see an output showing Node.js v22.x.x. To ensure Node.js is correctly installed, check the version by running:

node -v

This should return v22.x.x, confirming the installation was successful.


πŸ”„ Part 3: Install Another Version of Node.js

If you need to work with a different version of Node.js for another project, Volta makes it simple to install and switch between versions.

Step 1: Install Node.js v16

Let’s install Node.js v16 as another version to work with:

volta install node@16

Step 2: Verify Installation

After installation, run:

volta ls

This will list all installed Node.js versions. Run:

node -v

It should return v16.x.x, confirming that Node.js v16 is now active.


πŸ”„ Part 4: Switching Between Installed Versions of Node.js

You can easily switch between installed versions of Node.js using Volta.

Step 1: Switch to Node.js v22

To switch back to Node.js v22, run the following command:

volta install node@22

Step 2: Verify Active Version

Run the following command again to verify that v22 is active:

volta ls

And check the active version with:

node -v

You should see v22.x.x as the active version.

Summary of Version Switching

  • Installing a version: volta install node@<version>
  • Switching to a version: volta install node@<version>
  • Verifying active version: volta ls or node -v

πŸŽ“ Conclusion: Installing Node.js on Windows with Volta

With Volta installed on your Windows machine, managing Node.js versions becomes quick and easy. You can easily install different versions of Node.js, switch between them, and ensure that you’re using the right version for each project.

By following this guide, you can confidently set up Node.js in your development environment and maintain different versions as needed. Happy coding!