top of page

Node.js

     Node.js is a server JavaScript environment that uses an asynchronous event-driven model. We can build real-time website response. To begin with, servers push data to clients and only when there is data to push. If they push too much data, it will be an equally tedious process. Node.js runs JavaScript by leveraging V8 Google’s fast JavaScript engine for Chrome. It will create a runtime environment that pushes JavaScript into machine language giving Node.js speed. Node.js and asynchronous programming make Node.js more responsive. Event loop ensure data simply transmitted when it exists. Therefore, Node.js can normally run the program and leave out the heavy lifting. Event loop manages real-time communication without taking too much memory.

Reference

  1. M.cabrera, 2011, “Node.js presentation”, Slide share[online], Available: http://www.slideshare.net/martincabrera/node-js-presentation[2013,November 16]

  2. J.Bruce, 2013, "What is Node.JS and Why Should I Care? [Web Development]", Makeuseof[online], Available:http://www.makeuseof.com/tag/what-is-node-js-and-why-should-i-care-web-development/ [2014, January 22]

  3. T.Capan, 2013, "Why The Hell Would I Use Node.js? A Case-by-Case Introduction", Toptal[online], Available: http://www.toptal.com/nodejs/why-the-hell-would-i-use-node-js [2014, January 22]

Why use Node.js?

     The most importance requirement when you are start-up doing the next big thing and want to make sure you can scale quickly. Node.js  is also perfect for a fast performance and scalability. Node.js can handle thousands of these concurrently where PHP would just collapse.

How dose it work?

     The main idea of Node.js: use non-blocking, event-driven I/O to remain lightweight and efficient in the face of data-intensive real-time applications that run across distributed devices.

     Compared to traditional web-serving techniques where each connection or request spawns a new thread, taking up system RAM and eventually maxing-out at the amount of RAM available, Node.js operates on a single-thread, using non-blocking I/O calls, allowing it to support support tens of thousands of concurrent connections as show in figure2. 

     A quick calculation: assuming that each thread potentially has an accompanying 2 MB of memory with it, running on a system with 8 GB of RAM puts us at a theoretical maximum of 4000 concurrent connections, plus the cost of context-switching between threads. That’s the scenario you typically deal with in traditional web-serving techniques. By avoiding all that, Node.js achieves scalability levels of over 1M concurrent connections (as a proof-of-concept).There is, of course, the question of sharing a single thread between all clients requests, and it is a potential pitfall of writing Node.js applications. Firstly, heavy computation could choke up Node’s single thread and cause problems for all clients (more on this later) as incoming requests would be blocked until said computation was completed. Secondly, developers need to be really careful not to allow an exception bubbling up to the core (topmost) Node.js event loop, which will cause the Node.js instance to terminate (effectively crashing the program).The technique used to avoid exceptions bubbling up to the surface is passing errors back to the caller as callback parameters (instead of throwing them, like in other environments). Even if some unhandled exception manages to bubble up, there are mutiple paradigms and tools available to monitor the Node process and perform the necessary recovery of a crashed instance (although you won’t be able to recover users’ sessions), the most common being the Forever module, or a different approach with external system tools upstart and monit.

Figure2 Comparison of requests of tradition webserving and Node.js 

[Source:http://www.toptal.com/uploads/blog/image/50/toptal-blog-1_B.png]

bottom of page