What is Node.js And How It Works?

What is Node.js And How It Works?

Till today, you all have used javascript on client side only in your web applications for validation purpose, event handling functions or something else. Have you tried it on server side before ever?? Now you must be thinking, what nonsense I’m talking about. I’m just not joking because it’s time to do something crazy. After a lot of research and understanding the data structure of all scripting languages, Ryan Dahl decided to design such a server side software system that can run on Google’s V8 javascript engine and be able to create highly scalable, event driven and real time applications. It was named as node.js . Now you are worrying about “what is real time application”. Before we move on further detail about node.js , I’d like to introduce you with Real Time Applications.

What is Node.js And How It Works?

What are Real Time Applications??

Instead of letting you read the garbage definition of it, I focus on an effective example. Suppose you open your facebook account in two different browsers (Mozilla Firefox and Google Chrome). You’ve started chat in Mozilla Firefox and have sent a number of messages to the end user. Have you noticed that after hitting the enter key on chat box, the same message immediately appears in Google chrome chat box also without having a time delay. This is real time application in which the user does not need to wait for a single second to get the response from server.Real time applications is same as the cricket game in which you throw a ball and someone catch it in real time instead of waiting. Other examples of real time applications are live chatting, Voice Over Internet Protocol (VOIP), Online Games where scores get update before blinking our eyes.

So it was all about real time applications. Now come to Node.js . Actually Node.js is a server side javascript whose all programs are written in pure javascript. All browsers and every web application programmer are much familiar with javascript. By using javascript on both client and server side the browser reduces impendence mismatch created between two different programming environment.

Most of the web developers who haven’t heard about node.js, try to make a chat application using ajax and mysql that is totally nonsense. In this chat app, the message is stored in mysql table first and then displayed on the chat box of end user by ajax. The chat box calls ajax in every 1 second and fetch the recently sent messages from database. This makes the application so slow that increases the load on database server also. A highly scalable chat application can be developed using node.js and socket.io module that communicates browser to browser directly and pushes a message intensely on the browser.

Node.js Modules:

Although Ryan Dahl has given us a server side javascript platform to work with but he can’t reserve his whole life for node.js development. Actually node.js comes with a package manager or module manager by which we can install and use it’s modules as our application requirement. There are many modules have been developed by crazy node.js developers. We can find them on github repository.

Benefits of Node.js:

1. As javascript is the most popular language, So everyone can create node.js programs.
2. As we are using javascript on both client and server side in our web application so the browser reduces the impendence mismatch between two different programming environments.
3. On a single process, Node.js can handle thousands of connections.
4. It creates it’s own http server in run time that may be run on appropriate port defined by you in the program. So no need to install apache or some another.
This was a brief about node.js and I know you haven’t got very much about Node.js by reading this article but you will understand it very good after reading some further articles that I’m writing. In the next article I’m will be telling you about “how to install node.js on windows and linux system”.