Node Js

Node.js is a very powerful JavaScript-based framework/platform built on Google Chrome's JavaScript V8 Engine. It is used to develop I/O intensive web applications like video streaming sites, single-page applications, and other web applications. Node.js is open source, completely free.



Features of Node.js
Following are some of the important features that make Node.js 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 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.
·   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.
·     No Buffering − Node.js applications never buffer any data. These applications simply output the data in chunks.
·        License − Node.js is released under the MIT license.
Node JS Users : eBay, General Electric, GoDaddy, Microsoft, PayPal, Uber, Wikipins, Yahoo!, and Yammer to name a few.

Where to Use Node.js?

Following are the areas where Node.js is proving itself as a perfect technology partner.
·        I/O bound Applications
·        Data Streaming Applications
·        Data Intensive Real-time Applications (DIRT)
·        JSON APIs based Applications
·        Single Page Applications

Where Not to Use Node.js?

It is not advisable to use Node.js for CPU intensive applications.
A Node.js application consists of the following three important components −
·        Import required modules – We use the require directive to load Node.js modules.
Ex :
                           var http = require("http");

·        Create server − A server which will listen to client's requests similar to Apache HTTP Server.
Ex :
            http.createServer(function (req, res) {
            res.writeHead(200, {'Content-Type': 'text/plain'});
            res.end('Hello World\n');
            }).listen(4040);
·        Read request and return response − The server created in an earlier step will read the HTTP request made by the client which can be a browser or a console and return the response.
Ex :
            $ node <filaname>.js
Verify the Output. Server has started.
                    Server running at http://127.0.0.1:4040/
Node Package Manager (NPM) provides two main functionalities −
·      Online repositories for node.js packages/modules which are searchable on search.nodejs.org
·   Command line utility to install Node.js packages, do version management and dependency management of Node.js packages.
Installing modules using NPM
There is a simple syntax to install any Node.js module −
$ npm install <Module Name>
For example, following is the command to install a famous Node.js web framework module called express −
$ npm install express
Now you can use this module in your js file as following −
var express = require('express');


Comments

Popular Posts