logo
blog-image

Node.js is an open source, cross-platform runtime environment for developing server-side and networking applications. Node.js applications are written in JavaScript, and can be run within the Node.js runtime on OS X, Microsoft Windows, and Linux.

Node.js is a server side platform built on Google Chrome's JavaScript Engine (V8 Engine). Node.js was developed by Ryan Dahl in 2009 and its latest version is v0.10.36.


Features of Node.js

Asynchronous and Event Driven All APIs of Node.js library are asynchronous that is, non-blocking. It essentially means a Node.js based server never waits for an API to return data. The server moves to the next API after calling it and a notification mechanism of Events of Node.js helps the server to get a response from the previous API call.


Very Fast Being built on Google Chrome's V8 JavaScript Engine, Node.js library is very fast in code execution. JavaScript engines it compiles JavaScript directly into native machine code, while other languages PHP & Ruby, Java all have to run through an interpreter every time when they are accessed. 

Node will run your code as though it’s native application. So it screams with speed.

Single Threaded but Highly Scalable - Node.js uses a single threaded model with event looping. Event mechanism helps the server to respond in a non-blocking way and makes the server highly scalable as opposed to traditional servers which create limited threads to handle requests. Node.js uses a single threaded program and the same program can provide service to a much larger number of requests than traditional servers like Apache HTTP Server.

Node.js applications never buffer any data. These applications simply output the data in chunks.

How node.js come?

Basically it start from 2009 by Ryan Dahl. The idea came when Dahl saw a file upload progress bar on Flickr. The browser did not know how much of the file had been uploaded and had to query the Web server. Dahl wanted invent an easier way.

Finally Dahl presented Node.js at the inaugural European JSConf on November 8, 2009.

In 2011, a package manager was introduced for the Node.js environment called npm.
In June 2011, Microsoft and Joyent implemented a native Windows version of Node.js.

In January 2012, Dahl stepped aside, promoting coworker and npm creator Isaac Schlueter to manage the project.

In February 2015, the intent to form a neutral Node.js Foundation was announced. By June 2015, the Node.js and io.js communities voted to work together under the Node.js Foundation.

In September 2015, Node.js v0.12 and io.js v3.3 were merged back together into Node v4.0

As of 2016, the io.js website recommends that developers switch back to Node.js


How Node.js work?

Node is completely event-driven. Basically the server consists of one thread processing one event after another.

A new request coming in is one kind of event. The server starts processing it and when there is a blocking IO operation, it does not wait until it completes and instead registers a callback function. The server then immediately starts to process another event (maybe another request). When the IO operation is finished, that is another kind of event, and the server will process it (i.e. continue working on the request) by executing the callback as soon as it has time.

So the server never needs to create additional threads or switch between threads, which means it has very little overhead. If you want to make full use of multiple hardware cores, you just start multiple instances of node.js


How it can work fast?

First, Node is powered by Google’s V8 JavaScript Engine. The thing running you JavaScript code is the exact same thing the Chrome browser uses to run JavaScript code.

Second, When 100 people connect at once, rather than having different threads, Node will loop over those connections and fire off any events your code should know about. If a connection is new it will tell you .If a connection has sent you data, it will tell you .If the connection isn’t doing anything ,it will skip over it rather than taking up precision CPU time on it. Everything in Node is based on responding to these events. So we can see the result, the CPU stay focused on that one process and doesn’t have a bunch of threads for attention. There is no buffering in Node.JS application it simply output the data in chunks.


When we should use Node.js

Node.js is especially suited for applications where you'd like to maintain a persistent connection from the browser back to the server. Using a technique known as long polling, you can write an application that sends updates to the user in real time. Doing long polling on many of the web's giants, like Ruby on Rails or Django, would create immense load on the server, because each active client eats up one server process. When we use something like Node.js, the server has no need of maintaining separate threads for each open connection.

Node.js takes almost no system resources to serve a great many clients. Any time you want to do this sort of long-polling, Node.js is a great option.

The applications where use of nod.js is a good option -
Chat Room,Remote Control,Game applications etc…


Node.js vs jQuery

Anchor Now the question arise can node js replace jquery with node.js ?
The answer is NO. The only thing your browser can actually run, is Javascript. Of course you can use a bunch of libraries as well, but if you talk about node.js, the language is javascript too but you're running it on the server.
Let’s discuss some points on comparing both.

  1. Node.js enable server side code to be written in Javascript capability which can not be achieved by jQuery.

  2. Both are capable of consuming web service. The difference is jQuery will be doing it in client side while Node.js will be doing it in server side.

  3. The main difference is Node.js enables server scripting in javascript.

  4. In which Situation i should go with Node.js or JQuery ?

  5. Server side scripting, like replacement for PHP, ASP.NET we should go with Node.js .

  6. Node.js enable server side scripting in javascript where jQuery simplify client side scripting. Both are useful for a successful application.



Some list of real life applications in Node.js

  1. Walmart (Why Walmart is using Node.js )

  2. E-bay / PayPal ( Node.js at PayPal)

  3. Microsoft (Node.js Dev Center | Windows Azure) They have extensive support, in fact their Azure CLI tools are actually written in Node.js.

  4. LinkedIn (Exclusive: How LinkedIn used Node.js and HTML5 to build a better, faster app)

  5. Yahoo

  6. Google (Node at scale: What Google, Mozilla, & Yahoo are doing with Node.js)

  7. Yammer (now part of Microsoft) (Managing Node.js Dependencies and Deployments at Yammer - Yammer Engineering)

  8. Netflix has a series of blog posts on its use (Search results for node.js ) (Updated 2016-02-02)