How to Install Node.js and NPM on Windows

December 28, 2023

Introduction

Node.js is a runtime environment that includes everything you need to execute a program written in JavaScript. It's used for running scripts on servers to render content before it is delivered to a web browser.

Node Package Manager (NPM) is an application manager and repository for developing and sharing JavaScript code. It enables managing Node.js dependencies.

This guide shows several methods to install and test Node.js and NPM on Windows.

Tutorial on how to install, use, update and remove Node.JS and NPM (Node package manager)

Prerequisites

  • A user account with administrator access (or the ability to download and install software).
  • Access to the command prompt.
  • A text editor or IDE to run code and test Node.js.

Install Node.js and NPM on Windows via Node.js Installer

If you prefer using the GUI to install programs, Node.js has a downloadable installer on their official website. Follow the steps below to install Node.js and NPM on Windows via the installer.

Step 1: Download Node.js Installer

In a web browser, navigate to the Node.js Downloads page. Click the Windows Installer button to download the latest stable version with long-term support (LTS). The installer also includes the NPM package manager.

Node.js Windows installer download page

The file is saved in the Downloads folder by default.

Other versions of Node.js and NPM are available, so choose the appropriate one for your system and use case. Use the top tabs to switch from the LTS to the current version to test the newest features. If you are new to Node.js or don't need a specific version, choose LTS since it is tested and stable.

Step 2: Install Node.js and NPM

After downloading the installer, follow the steps below:

1. Launch the installer by double-clicking the downloaded file.

2. The Node.js Setup Wizard starts with the welcome screen.

Node.js setup wizard welcome screen

Click Next to proceed.

4. Review the end-user license agreement and click the checkbox to accept the terms and conditions.

Node.js setup wizard end-user license agreement

Click Next to continue.

5. The installer asks to choose the installation location.

Node.js setup wizard install location

Leave the default location for a standard installation and click Next to proceed.

6. Select components to include or remove from the installation. The default options install Node.js, NPM, corepack, online documentation shortcuts, and add the programs to PATH.

Node.js setup custom setup

Customize the setup or click Next to accept the default values.

7. The following section shows the total required space for the installation and the available space on disk.

Node.js setup disk space requirements

Click OK to proceed. Select a different disk or install fewer features if the installation does not allow proceeding.

8. Choose whether to install additional dependencies for compiling native modules. Some NPM modules compile from C/C++ and require additional tools to function correctly (Python, Visual Studio Build Tools, and Chocolatey).

Node.js setup tools for native modules

If you use such modules, select the checkbox and click Next. The selection of this option starts an installation script after the Node.js installation is complete.

For a simple installation, skip this step and click Next to proceed.

7. Click the Install button to start the installation.

Node.js setup ready to install

8. The installer prompts for administrator confirmation to make changes to the device.

Node.js install administrator changes

Enter the administrator password if prompted and click Yes to continue.

9. The installation takes some time. When it is complete, the final screen shows a success message.

Node.js setup install finished

Click Finish to complete the installation and close the installer.

Note: If you selected to install native tools in step 8, closing the installer automatically starts a PowerShell script to install the listed tools.

Step 3: Verify Installation

To verify Node.js installed successfully, run the following command in a command prompt or PowerShell:

node -v

The command shows the Node.js version installed on your system. Use the following command to check for NPM:

npm -v
node -v and npm -v cmd output

Note: If NPM is not recognized or properly installed, command prompt displays the following error message: npm: command not found. Check if NPM is added to path, or if there are multiple versions installed on the system.

Install Node.js and NPM on Windows via Chocolatey

Chocolatey is a Windows package manager. It can be used to install programs such as Node.js with NPM. Follow the steps below to install Node.js and NPM using Chocolatey.

Note: Chocolatey is not available on Windows by default. If you need to install it, follow our guide to install Chocolatey on Windows.

Step 1: Install Node.js and NPM

To run the installation command, do the following:

1. Open the command prompt as an administrator.

2. Run the following command to install Node.js and NPM:

choco install nodejs
choco install nodejs CMD output

When prompted to run the installation script, press y and Enter to continue the installation. Wait for the installation to complete before proceeding.

3. Reset environment variables to add Node.js and NPM to PATH. Use the following command:

refreshenv
refreshenv CMD output

The command resets the environment variables, which enables running both programs from the terminal.

Step 2: Verify Node.js and NPM installation

To verify that Node.js is installed correctly, run the following command in a new command prompt session:

node -v

Check the NPM installation with:

npm -v

Both commands display the program version.

Test Node.js Installation

There are several ways to test a Node.js installation. The simplest way is to create a Hello World JavaScript program and run it using Node.js:

1. Open a text editor or IDE.

2. Add the following code to the file:

console.log("Hello, world!")

The code is a simple program that prints "Hello, world!" to the console.

3. Save the script with a .js extension.

4. Run the program from an IDE to see the results. Alternatively, navigate to the directory where the file is located and use the following command:

node [file_name].js
node hello.js CMD output hello world

The command prints the message to the console, indicating that the Node.js installation works successfully.

Conclusion

You should now be able to install the Node.js framework and the NPM package manager. You also wrote your first Node.js JavaScript program.

Next, see the differences between Yarn and NPM, two different Node.js package managers.

Was this article helpful?
YesNo
Milica Dancuk
Milica Dancuk is a technical writer at phoenixNAP with a passion for programming. With a background in Electrical Engineering and Computing, coupled with her teaching experience, she excels at simplifying complex technical concepts in her writing.
Next you should read
How to Get Current Date & Time in JavaScript
December 6, 2023

The Date object is useful for checking the date that visitors arrive at your website. This guide will walk...
Read more
How to Connect to MySQL from Windows Command Line
May 3, 2019

MySQL is a popular and open-source relational database application. Many servers make use of MySQL, to...
Read more
How to Restart Windows Server 2016 - Reboot Commands
October 22, 2018

When a computer runs for a long period of time, applications and operating system features can become...
Read more
How to Configure Windows Server 2012 Firewall
September 17, 2018

Firewalls have become an essential part of every network that has access to the Internet. Without firewalls...
Read more