How to Install Node.js and npm on Windows

Node.js is a popular JavaScript runtime designed to execute JavaScript code on the server-side. While it is commonly used for backend applications, it is also widely used for full-stack and frontend solutions. npm (Node.js’s default package manager) holds the world’s largest software registry, making it an essential tool for developers. This guide provides a step-by-step process for installing the latest version of Node.js (currently version 21.x) and npm on Windows.

Methods

You can install Node.js and npm using the following methods:

  • Installation from the Official Node.js Website
  • Installation using Windows Package Manager (Chocolatey)
  • Installation using NVM (Node Version Manager)

1. Installation from the Official Node.js Website

The easiest way to install the latest version of Node.js is by downloading it from the official Node.js website.

Step 1: Download Node.js

  • Go to the official Node.js website: https://nodejs.org
  • Choose the appropriate version for Windows (LTS or Current) and download it.

Step 2: Start Node.js Installation

  • Double-click the downloaded .msi file.
  • The installation wizard will open. Click Next.
  • Select “I accept the terms in the License Agreement” and click Next.
  • Choose the installation directory (the default is C:\Program Files\nodejs\) and proceed by clicking Next.
  • Click Install and wait for the installation to complete.
  • Once the installation is complete, click Finish.

Step 3: Verify Installation

After the installation, open the Command Prompt and run the following commands to verify that Node.js and npm are installed correctly:

node --version
npm --version

These commands will display the installed versions of Node.js and npm.


2. Installation using Windows Package Manager (Chocolatey)

Chocolatey is a package manager for Windows that allows for quick and easy installation of Node.js.

Step 1: Install Chocolatey

To install Chocolatey, open a PowerShell window with administrator privileges and run the following command:

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

Step 2: Install Node.js

After installing Chocolatey, you can install Node.js by running the following command:

choco install nodejs-lts

This command will install the LTS (Long Term Support) version of Node.js.

Step 3: Verify Installation

To verify the installation, run the following commands in the Command Prompt:

node --version
npm --version

3. Installation using NVM (Node Version Manager)

NVM (Node Version Manager) is a useful tool for managing multiple Node.js versions and works on Windows as well.

Step 1: Download and Install NVM

Download the Windows version of NVM from here.

Run the downloaded .exe file to install NVM.

Choose the directory where NVM will be installed and the directory where Node.js versions will be stored during installation.

Once the installation is complete, restart your computer.

Step 2: Install a Node.js Version

After installing NVM, you can install the desired version of Node.js using the following command:

nvm install 21

This will install Node.js version 21.x.

Step 3: Select the Node.js Version to Use

To specify which Node.js version to use, run the following command:

nvm use 21

Step 4: Verify Installation

Finally, verify that the installation was successful by running the following commands:

node --version
npm --version

Conclusion

This guide covered three different methods to install Node.js and npm on Windows: using the Official Website, Chocolatey, and NVM. Depending on your needs, you can choose one of these methods. Node.js and npm are core components of modern JavaScript applications, and ensuring proper installation is crucial for the smooth operation of your projects.

Previous Article

How to Install Node.js and npm on Linux

Next Article

What is Python? An Introduction to the Python Programming Language | 1

Subscribe to our Newsletter! 📬

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨