Nodejs: An Introduction and its Uses

what is nodejs and its uses

Node.js was built on the Google Chrome’s JavaSript Engine (V8), which is a server-side platform. It was developed by Ryan Dahl in 2009. The main purpose of Node.js was to build fast and scalable network applications. It is also event-driven, efficient, non-blocking I/O model and perfect real-time application that is capable for running on many distributed computers.

Node.js is platform independent, which means, it can run on any platform like Linux, Windows, etc. It is an open source application and can run on cross-platform run-time environment for both server-side and networking applications. It consist of rich library with various JavaScript modules for web applications and extensibility use.


Why Node.js and not any other ?

Well, when it comes to dynamic handling of web pages, then Node.js is more powerful. You can say that PHP and can handle Dynamic Rendering of pages but the problem comes with asynchronous web page handling.

In simple words, when a php or server send’s a web page to browser then it waits for the receiver to open and read the file and then process another request. So it take a little time in this process. While in Node.js , as soon as task is sent by server, the Server is ready to handle the next response.

Another major reason that you should be using Node.js is that it’s single-threaded, non-blocking, asynchronously programming and very memory efficient.

Features in Node.js

  • It can create, open, close, read, write and delete files on server easily.
  • It can add, modify and delete data in your database.
  • It can generate dynamic web page content.
  • It uses JavaScript on the server.
  • Node.js can run on various platforms, it’s free and have open source server environment.

Advantages of using Node.js

  • Node.js removes the waiting time and continues to process the next request.
  • It runs on single-threaded, non-blocking, asynchronously programming, which is very memory efficient.
  • Node.js is designed to never buffer any data. The application have large output in data.
  • With Google’s V8 JavaScript Engine, the Node.js library is very fast and easy to handle.

Disadvantage of Node.js

Node.js is not suitable for CPU intensive or CPU intensive like applications.

Download and install Node.js for your computer

The source code is written in javascript and we will use an interpreter for executing our Node.js javascript code. You can download it from the official link . It is also advised to use Visual Studio Code for better visibility and understanding the work behind execution of code. Click here to download from the official link:

Verifying Installation

After download and installing, you can check it at your system. Simply create and save a file with sample.js name and save.  Type the below code on Visual Studio Code Terminal:

Console.log(“Hello and Welcome to DigitalGyan”)

It’s not compulsory to use ; (semi-colon) at the end. But as a programmer you should use it.

After that type:  

node sample.js

If everything is working, then you will get the Output

Hello and Welcome to DigitalGyan

Creating a Simple Web Server on your local machine

To create a simple web page, follow the steps below:

Create a file with name sample.js and save it

Write the following code:

Var http = require(‘http’);

# require(): This method is used to add a header file, which consist of pre-defined functions.

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

# the createServer function is used to create a Server that will handle request and response method to your local browser.

#res.write is used to generate a response status with 200, “OK” and the type of file which server will send.
# res.end is the output that will be returned.

We’ll cover more about the code in the later course.

Save the file and open terminal and type

node sample.js

Now, you computer becomes a server.

After this, you can open your browser and type the following address https://localhost:8080 , you will get the output.

nodejs example

If anyone tries to connect with this port 8080 to your computer. This will display the same output message.

Is JavaScript necessary for Node.js?

Node.js was originally built on the purpose for extending the features of Java programming. But at the same time, it must handle the request and response, which can be in XML or other languages. Hence, a newer version of ECMA script was written. And later that it was converted to Javascript programming.

Therefore, Javascript is given more focus for Web Development in Node.js .

Which Big Companies Uses Nodejs?

There is no such a deal that only big tech giant Companies uses Nodejs, even many small companies and start-ups also use it. Some of the Big Companies that rely on Nodejs are eBay, GoDaddy, General Electric, Microsoft, PayPal, Uber, Wikipins, Yahoo, Netflix, etc.


When to use Node.js?

If you have these conditions, then Node.js is the best tool which you should use. These conditions are:

  • Data Intensive Real-time Applications (DIRT)
  • Single Page Applications
  • I/O bound Applications
  • JSON APIs based Applications
  • Data Streaming Applications

Show More

Leave a Reply

Back to top button