Node.js is an environment that allows developers to use JavaScript Language and run executable code outside a web browser.
It enables fast development and execution of web servers in JavaScript. It also has node package manager that allows one to store a lot of libraries and use them by call back.

Node.js version 16 was released in April 2021. It includes the following features;

  • Active Long Time Support (LTS)
  • Assertion testing with strict assertion and Legacy Assertion now stable
  • Increased command line options
  • Cluster module to invoke connections between example, parent and child processes
  • Global objects that are available in all modules, e.g, __dirname, __filename.
  • Events where, when an EventEmitter object emits an event, all of the functions attached to that specific event are called synchronously

Prerequisites of this , is that you have basic understanding of JavaScript language.

In this guide I will show you how to;

  • Install Node.js 16 on Windows 10 / Windows 11
  • Download additional tools needed to run Node.js
  • Type some scripts using the Node.js command line shell
  • Run a simple script on the web browser

Install Node.js 16 on Windows 10 / Windows 11

Go to the official website of node.js. Click on version 16 LTS to download the setup

The download starts immediately upon clicking on the link.

Find the location of the file downloaded and double-click on it to open the setup wizard. Follow the installation prompt like accepting license agreement.

Choose the destination folder to install the program

Next up will be to customize your setup. That is, Choose what you want to leave out, I would recommend to continue with the default. It even sets up the path environment which saves on time while installing.

Next will be to choose if you want to install the Node.js native modules including chocolatey and python. Hence, Mark the checkbox to allow the installation once the main installation is done.

The installation now will proceed to finish.

Once its done, A new window opens more likely a command prompt for node.js that will require you to press any key to continue with the installation

Once you press a key, a new Administrator: Windows PowerShell window opens which will now start installing all the necessary tools for node.js starting with chocolatey.

The installation can take a while depending on how fast your internet or system is. Thus, you can minimize it and open the Node.js command prompt.

Using Node.js 16 on Windows 10 / Windows 11

You can find it at the start menu at the top as it is the most recent app installed.

The Node.js command prompt opens and you can start by checking its version by using node -v script.

Then to directly go into the Node.js environment. Type the code node then press Enter.

You can then try some general scrip like printing ‘Hello World’ by using console.log("Hello World") code then press Enter

Create a simple Web Server

Open your notepad, The normal notepad text editor on windows. Then paste this code;

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

As shown in the notepad below

Save the document with an extension filename of .js as shown below in your preferred location.

Once you ahve saved your document, you can close it. Retrive it from your saved location but do not open it. Press the SHIFT key then right-click on the folder where you file is. It will show you different options from the normal right-click button.

Click on the Open PowerShell window here.

Windows PowerShell Opens as shown below. Type in node followed with the filename hello.js then press Enter.

It shows server running at what host and what port.

Then go to your browser and type in the hostname and port as it appears on the Windows PowerShell. You can as well copy and paste it on your search bar. then press Enter.

A webpage opens with the statement Hello World. Your server runs successfully.

Conclusion

In this guide we have installed Node.js on windows then selected to install other native tools necessary for Node.js to run in C++ environment. We have been able to build a web server by use of a simple script that incorporates different codes required to run a web page like require http.

This are the basic stuff that are beginner friendly with respect to Node.js. As we go along we will discover far much tools to use with Node.js.

More guides on Windows:

LEAVE A REPLY

Please enter your comment!
Please enter your name here