How to Download & Install Node.js and NPM on Windows

โšก Smart Summary

Node.js installation on Windows uses the official MSI installer or the Chocolatey package manager, both of which bundle NPM. After setup, a simple HTTP server script confirms the runtime serves a Hello World response in the browser.

  • ๐ŸชŸ Windows Installer: The MSI installer from nodejs.org installs Node.js and NPM together.
  • ๐Ÿ“ฆ Chocolatey: The Windows package manager installs Node.js with a single PowerShell command.
  • โš™๏ธ Hello World: A require(‘http’) server listens on port 8080 and returns a response.
  • ๐Ÿ”ข Version Check: Running node -v and npm -v confirms the installed versions.
  • ๐Ÿง WSL2 Option: Microsoft recommends Node.js on WSL2 for Linux-style development workflows.
  • ๐Ÿค– AI Setup: AI assistants generate install commands and starter server scripts quickly.

Download and Install Node.js and NPM on Windows

To start building your Node.js applications, the first step is the installation of the Node.js framework. The Node.js framework is available for a variety of operating systems right from Windows to Ubuntu and OS X. Once the Node.js framework is installed, you can start building your first Node.js applications.

Node.js also has the ability to embed external or extended functionality by making use of custom modules. These modules have to be installed separately. An example of a module is the MongoDB module, which allows you to work with MongoDB databases from your Node.js application.

How to Install Node.js on Windows

The first step in using Node.js is the installation of the Node.js libraries on the client system. Below are the steps to download and install Node.js in Windows:

Step 1) Download Node.js Installer for Windows.

Go to the site https://nodejs.org/en/download/ and download the necessary binary files. In our example, we are going to download Node.js on Windows with the 32-bit setup files.

Install Node.js on Windows

Step 2) Run the installation. Double click on the downloaded .msi file to start the installation. Click the Run button on the first screen to begin the installation.

Install Node.js on Windows

Step 3) In the next screen, click the โ€œNextโ€ button to continue with the Node.js download and installation.

Install Node.js on Windows

Step 4) Accept the terms and conditions. In the next screen, accept the license agreement and click on the Next button.

Install Node.js on Windows

Step 5) Set up the path. In the next screen, choose the location where Node.js needs to be installed and then click on the Next button.

  1. First, enter the file location for the installation of Node.js. This is where the files for Node.js will be stored after the installation.
  2. Click on the Next button to proceed ahead with the installation.

Install Node.js on Windows

Step 6) Select the default components to be installed. Accept the default components and click on the Next button.

Install Node.js on Windows

Step 7) Start the installation. In the next screen, click the Node.js install button to start installing on Windows.

Install Node.js on Windows

Step 8) Complete the installation. Click the Finish button to complete the installation.

Install Node.js on Windows

Note: Windows now recommends that developers use Node.js with WSL2 (the Windows Subsystem for Linux) for Linux-style development workflows.

How to Install NPM on Windows 10/8/7

The other way to install Node.js on any client machine is to use a โ€œpackage manager.โ€ On Windows, the NPM (Node Package Manager) download is known as Chocolatey. It was designed to be a decentralized framework for quickly installing applications and tools that you need.

For installing NPM on Windows via Chocolatey, the following steps need to be performed.

Step 1) Installing Chocolatey โ€“ The Chocolatey website has very clear instructions on how this framework needs to be installed.

  • The first step is to run the below command in the command prompt window. This command is taken from the Chocolatey website and is the standard command for installing Node.js via Chocolatey.
  • The below command is a PowerShell command which calls the remote PowerShell script on the Chocolatey website. This command needs to be run in a PowerShell command window.
  • This PowerShell script does all the necessary work of downloading the required components and installing them accordingly.
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin

Install NPM on Windows 10/8/7

Step 2) The next step is to install Node.js to your local machine using the Chocolatey package manager. This can be done by running the below command in the command prompt.

Install NPM on Windows 10/8/7

If the installation is successful, you will get the message of the successful installation of Node.js.

Note: If you get an error like โ€œC:\ProgramData\chocolatey\lib\libreoffice\tools\chocolateyInstall.ps1โ€, then manually create the folder in the path.

Running your first Hello World application in Node.js

Once you have Node.js downloaded and installed on your computer, let us try to display โ€œHello Worldโ€ in a web browser. Create a Node.js file with the file name firstprogram.js.

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.end('Hello World!');
}).listen(8080);

Code Explanation:

  1. The basic functionality of the โ€œrequireโ€ function is that it reads a JavaScript file, executes the file, and then proceeds to return an object. Using this object, one can then use the various functionalities available in the module called by the require function. So in our case, since we want to use the functionality of HTTP, we are using the require(http) command.
  2. In this 2nd line of code, we are creating a server application which is based on a simple function. This function is called whenever a request is made to our server application.
  3. When a request is received, we are asking our function to return a โ€œHello Worldโ€ response to the client. The writeHead function is used to send header data to the client, while the end function closes the connection to the client.
  4. We are then using the server.listen function to make our server application listen to client requests on port no 8080. You can specify any available port here.

Executing the code

  1. Save the file on your computer: C:\Users\Your Name\firstprogram.js
  2. In the command prompt, navigate to the folder where the file is stored. Enter the command Node firstprogram.js.

First Hello World Application in Node.js

  1. Now, your computer works as a server! If anyone tries to access your computer on port 8080, they will get a โ€œHello World!โ€ message in return.
  2. Start your internet browser, and type in the address: http://localhost:8080

Output:

First Hello World Application in Node.js

FAQs

Node.js is the runtime that executes JavaScript outside the browser. NPM (Node Package Manager) installs and manages packages. Installing Node.js also installs NPM automatically.

Open Command Prompt and run node -v to print the Node.js version, then run npm -v to print the NPM version installed on your machine.

Choose LTS (Long Term Support) for most projects because it is stable and maintained longer. Pick Current only when you need the newest experimental features.

Yes. Microsoft recommends running Node.js on WSL2 for Linux-style workflows. Install a Linux distribution, then use a version manager such as nvm to install Node.js.

A version manager such as nvm-windows lets you switch between multiple Node.js versions per project. Remove any existing installation first to avoid conflicts.

No. The official Node.js MSI installer bundles NPM, so it installs automatically with Node.js. You can later update it by running npm install -g npm.

Yes. AI assistants such as ChatGPT generate the correct install commands for Windows, explain PATH errors, and produce starter scripts, which speeds up first-time setup.

Yes. GitHub Copilot autocompletes a require(‘http’) server that listens on a port and returns a Hello World response, letting you test the installation in seconds.

Summarize this post with: