Saturday, June 7, 2014

Node.js (Server Side JavaScript)

Server Side JavaScript


Node.js is a  platform for scalable server-side and networking applications. Node.js applications are written in JavaScript, and can be run within the Node.js runtime on Mac OS X, Windows and Linux 

 >> maximize throughput
 >> maximize efficiency
 >> using non-blocking I/O and asynchronous events
 >> single-threaded, although Node.js uses multiple threads for file and network events. 
 >>The HTTP and socket support that causes node act as a web server without additional web server Software as IIS etc
>> able to scale to millions of concurrent connections
     it uses the Google V8 JavaScript engine to execute code.

Traditional web  techniques require each request to  creates a new thread which caused much usage of server RAM. the cost of context-switching between threads is much
But Node.js  works on a single-thread, using non-blocking I/O calls, allowing it to support tens of thousands of concurrent connections, The design of sharing a single-thread between all the requests means it’s good at building highly concurrent applications. Node.js brings a new element to the mix in the form of an event-driven focus on the server-side. Client-side operational methods simply aren't efficient enough for the current and forthcoming generations of web systems. Node.js pushes data to clients if and only when appropriate.

Why Node.js
>  PayPal reported: double the number of requests per-second and reduced response time by 35% or 200 milliseconds.
>  WalMart Labs had a bumper launch with Node.js in 2013, where they put all of their Mobile traffic through Node.js on black-friday, the busiest shopping period of the year.
The team at WalMart Labs live tweeted against #nodebf tag showing the performance of the Node.js application. On Black Friday the WalMart servers didn’t go over 1% CPU utilisation and the team did a deploy with 200,000,000 users online.
> Similarly Groupon re-implemented their system in Node.js which resulted in page load times dropping by a whopping 50%.
> The old story of linkedin where moving to Node.js from Rails for their mobile traffic, reducing the number of servers from 30 to 3 (90% reduction) and the new system was up to 20x faster.
Easy to modify and maintain

> Node.js programs are developed using JavaScript, this means that the silos that existed between frontend developers and backend developers are now broken down, and this results in significant efficiencies in the development process. With Node.js it’s possible to merge web and backend teams into one unit which makes things much more efficient. 

The Future of Node.js

Eran Hammer announced at NodeDay ( that WalMart are planning to use Node.js across all eCommerce by the end of 2014.

PayPal are rolling out Node.js across their entire web application and Node.js will be used almost everywhere within 2 years.

Although Google have not publicly come out talking about their use of Node.js, there is evidence that they are using it, a simple search on linkedin shows almost 200 people in google with Node.js on their profile. According to an article on VentureBeat: “Googlers are definitely working on Node.js projects

Yahoo are a long way down the line with Node.js and have 200 developers doing Node.js full time with 800 public modules and 500 private ones.

Application Areas 

The Internet of Things
Payment Processing
Social Media
Realtime Services


As a new technology,  has some drawbacks
> high rate of change in node js library that cause lot of versioning problem /issues to developer/programmers

> Asynchronous and event-driven code inherently adds more complexity to the code versus a synchronous code .Code can get easily messy and confusing. To make your Node.js code run well you will need to use a lot of anonymous functions and callbacks (more on this in a bit!). These callbacks get increasingly deeper as your application gets larger resulting in the code being more complicated to read and debug.

> there a few hosting provider . Lots of problems may occure to host node js app with your current web hosting provider

Application Development 
     > With express.js (node.js +express.js  both server side with jade / ejs render engine)
     > Angular js as client end & Node js as backend. Nice application can be developed using angular js for consuming rest of node.
           Angular js  + Node js + mssql/mysql/mongodb/..

development can be started with

Some examples /tutorials : -

Source: Internet