Node.js


Didn’t want the Node.js peeps to feel left out. So here it is.

Node.js is a free, open-sourced, cross-platform JavaScript run-time environment that lets developers write command line tools and server-side scripts outside of a browser.

nodejs

Node.js runs the V8 JavaScript engine, the core of Google Chrome, outside of the browser. This allows Node.js to be very performant.

A Node.js app is run in a single process, without creating a new thread for every request. Node.js provides a set of asynchronous I/O primitives in its standard library that prevent JavaScript code from blocking and generally, libraries in Node.js are written using non-blocking paradigms, making blocking behavior the exception rather than the norm.

When Node.js performs an I/O operation, like reading from the network, accessing a database or the filesystem, instead of blocking the thread and wasting CPU cycles waiting, Node.js will resume the operations when the response comes back.

This allows Node.js to handle thousands of concurrent connections with a single server without introducing the burden of managing thread concurrency, which could be a significant source of bugs.

Node.js has a unique advantage because millions of frontend developers that write JavaScript for the browser are now able to write the server-side code in addition to the client-side code without the need to learn a completely different language.

In Node.js the new ECMAScript standards can be used without problems, as you don’t have to wait for all your users to update their browsers – you are in charge of deciding which ECMAScript version to use by changing the Node.js version, and you can also enable specific experimental features by running Node.js with flags.

Enough with the Gyaan! Let’s see how to install Node.js on Windows 10!

The first steps in using Node.js is the installation of the Node.js libraries on the client system. To perform the installation of Node.js, perform the below steps;

Step 1) Go to the site https://nodejs.org/en/download/ and download the necessary binary files. In our example, we are going to the download the 64-bit setup files for Node.js.

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

Step 3) On the next screen, click the “Next” button to continue with the installation

Step 4) On the next screen Accept the license agreement and click on the Next button.

Step 5) On 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.

Step 6) Accept the default components and click on the next button.

Step 7 On the next screen, click the Install button to start the installation.

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

Running your first Hello world application in Node.js

Once you have downloaded and installed Node.js on your computer, let’s try to display “Hello World” in a web browser.

Create file Node.js with file name helloworld.js

var http = require('http');

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


Executing the code

  1. Save the file on your computer, something like: D:\Roopak\helloworld.js

Open Command Prompt, navigate to the folder where the file is stored. Enter the following command

Node helloworld.js

  1. Now, your computer has been upgraded to work as a web server 😉 If anyone tries to access your computer on port 1979, they will get a “Hello World!” message in return!
  2. Start your web browser, and type in the address: http://localhost:1979

In your Web Browser

It’s cool, Right? Enjoy. You are now a web-master.


Follow us on our Official Social Media Platforms.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s