Wednesday, August 26, 2015

What is Node.js???

Hi friends,

Now a days there is a new word in the market called Node.js.

What is node.js?
What is the use of node.js?
How can we use node.js in visual studio?
What are the benefits of using it?

 There are a lot of questions comes in mind.  we will discuss all , but first of all lets find out what do we mean about node.js Node.js is an open source, cross-platform runtime environment for server-side and networking applications.

Node.js® is a platform built on Chrome's JavaScript run time for easily building fast, salable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. Node.js is open source, completely free, and used by thousands of developers around the world.

So how node.js is different from the others, to get the details of it lets have a look on the below diagram.

Node.js Vs Traditional 

This means instead of for each process each request node js will serve all the request using a single thread. Node.js operates on a single thread, using non-blocking I/O calls, allowing it to support tens of thousands of concurrent connections without incurring the cost of thread context-switching. The design of sharing a single thread between all the requests means it can be used to build highly concurrent applications. The design goal of a Node.js application is that any function performing I/O must use a callback.

A downside of this approach is that Node.js doesn't allow scaling with the number of CPU cores of the machine it is running on without using an additional module such as cluster,

Following are few of the important features which are making Node.js as the first choice of software architects.

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 a API to return data. Server moves to next API after calling it and a notification mechanism of Events of Node.js helps server to get 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.

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

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

So we have now know that where the node,js is ideal. There are also some area where the node.js should not be avoided like

Application with heavy server side processing and business logic

Applications with large \relational database connections.

And large client and server side technology based applications.

Node.js can be installed from below locations

For Windows


In windows Use the MSI file and follow the prompts to install the Node.js. By default, the installer uses the Node.js distribution in C:\Program Files\nodejs. The installer should set the C:\Program Files\nodejs\bin directory in window's PATH environment variable. Restart any open command prompts for the change to take effect.

Here is a simple application on Node.js

This simple web server written in Node responds with "Hello World" for every request.

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '');
console.log('Server running at');

To run the server, put the code into a file example.js and execute it with the node program from the command line:

% node example.js

Server running at

For tools in Visual studio you can check the below link to get more details. Node.js Tools for Visual Studio

I hope you all have got some basic information about Node.js. I will come up with some more details and sample code in Node.js in the coming articles. For any more details you can directly visit the official site of Node.js

Thanks & Regards
Anil Kumar Pandey
Microsoft MVP, Microsoft MCC, DNS MVM