Node.js is a run-time surrounding that consists of the whole thing you want to execute an application written in JavaScript. It’s used for jogging scripts at the server to render content material earlier than its miles added to an internet browser, so install Node Js in windows and enjoy its features.

NPM is a “package deal manager” that makes putting in Node “packages” speedy and easy. A package deal is only a code library that extends Node by including beneficial features. For example, the “request” package deal simplifies the manner of creating HTTP requests so that you can without difficulty get net assets from different sites.

In addition to choosing whether to install under Windows or WSL, some additional options must meet when installing Node js. We recommend using a version manager because the version changes very quickly.

Node Version Manager, also known as NVM, is the most popular way to install multiple versions of Node.js, but it only works on Mac/Linux, not Windows.

 How To Install Node JS In Windows?

Consider replacing version managers, which will also introduce in the next section.

Prerequisites

You have to have a little familiarity with a utility that helps you to problem command-line instructions.

For example, the Windows Command Prompt, PowerShell, Cygwin, or the Git shell (that you get while you set up Github for Windows).

The steps to install Node Js in windows are as follows:-

  • Open this link https://nodejs.org/en/download/ in your Internet browser and pick the download now link.
  • Download the nvm-setup.zip record.
  • After downloading, open the zip record after which open nvm-setup.exe.
  • The Setup-NVM-for-Windows installation wizard will guide you through the installation steps, including choosing the directory to install nvm-windows and Node js.
  • After the installation is complete, open PowerShell and try to use Windows-nvm to list the currently installed version of Node (they should not be there currently): nvm ls
  • Install the latest version of Node. js (to see the new and improved features, but more likely to have problems than the LTS version:
nvm install Latest
Windows is now recommending that developers use Node.js with WSL2(the Windows subsystem for Linux) 

Installation of Latest Stable LTS Version

  • First install the latest stable LTS version of Node.js by checking the current LTS version number (recommended): nvm list available, and then set the LTS version number to: nvm install (replace Number, for example: nvm install 12.14. 0)
  • List of installed node versions: nvm ls … You should now have the two versions you just installed, please refer to the list.
  • After setting the Node.js version number you need, enter: nvm use to select the version you want to use (replace with numbers, for example: nvm use 12.0).
  • Get the Node.js version Use the Node js you want to use for the project, create a mkdir NodeTest project directory and enter the NodeTest cd directory, then enter nvm use and replace it with the version number you want to use (for example, .v10.16. 3` )

Version Verification

The npm version is installed by the following command:

Testing Node JS and NPM on Windows using CMD
npm -v

or

node -v 

This version will automatically charge to the npm version assigned to your current Node.js version.

Alternative version managers to install node js on windows

Although windows-nvm is currently the most popular node version manager, some alternatives worth considering: 1-nvs (node version switcher), a cross-platform nvm alternative that can integrate with VS Code.  2-Volta is a new version manager from the LinkedIn team that promises improved speed and cross-platform support.

To Volta as a model manager (rather than windows-nvm), visit the “Install Windows” phase of the “Getting Started” manual. Then download the Windows Installer and run it in keeping with the setup instructions. Therefore install Node Js in windows by these steps.

Installing Node Js is not sufficient but for any situation, we need to know how to uninstall it also.

How To Run Your First Program In Node JS

Once you have done with all the processes mentioned above, then it’s time to try your first program in node js. Let’s start with a program in node js to display “Hello World” in your web browser. Looks cool, right?

Create file Node.js with your file name as firstprogram.js

var http = require('http');

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

Now it’s time for execution!

  • Just save your file on your computer: C:\Users\Your Name\ firstprogram.js
  • Now, open your cmd and navigate to the folder where you have saved the file and enter the command as:
node firstprogram.js

Hurray! It’s done, now your computer works as a server. If you try to access your computer using port 8080 then you’ll get “Hello World” on the screen.

  • Open your browser and type: http://localhost:8080

Now let’s look into the output…

Output

Install Node.js - NPM on Windows

Yeah! We achieved our goal, congrats on successfully completing your first program using node js.

Uninstall Node and NPM

Uninstall Node.js and NPM in the same way as most Windows programs:

Open the Windows Control Panel and select Programs and Features. After that just click Uninstall Program and now, select Node.js and click the delete link. Hence install Node Js in the window by the proper steps given above and uninstall it whenever you want.

Categorized in: