Node.js, what is that?

Published Wednesday, October 26, 2011 10:30 PM

Node.js is just about the hottest new language on the horizon. It also has some puzzling catch-phrase such as "JavaScript on the server side". It is so hot and so puzzling that I am compelled to commit one hour to watch the video sit on the home page of Node.js web site.

One hour video is long by any standard, but the presentation guy and Node.js creator Ryan Dahl breezed it through without one single slide.

He joked, he coded and typed command lines, he demoed a crappy chat program written in about 5 lines using Node.js. (Ouch, this tech world was and still is dominated by wiz kids, almost chrismatic, not a bit nerdy.)

However I was still confused even after the one-hour video. What the heck is Node.js? Why on earth we have to create our own servers?

The statement in big font after the video does not seem to help much. As the following it goes:

"Node's goal is to provide an easy way to build scalable network programs. ... Node tells the operating system (through epoll, kqueue, /dev/poll, or select) that it should be notified when a new connection is made, and then it goes to sleep. If someone new connects, then it executes the callback. Each connection is only a small heap allocation."


Searching around, I found quite a lot of examples where cool guys flaunting their cool code, however little clear explanations.

Searching more, I found quite a lot of insights and analysis, predications and dismissions. A testimony of how Node.js has caught the short attention span of the highly excitable yet unforgiving tech community.

Eventually, I came to my senses (at least I think) what Node.js does, what makes it special.

1. Node.js handle things asynchronously. The word "asynchronous" has been a sort of cliche. The big A in AJAX, for example, stands for "Asynchronous". However, the asyc part of AJAX comes from the client side, in that client (a browser) sends requests to server and still serves the page while waiting for the server to come back for a response. The server process requests one at a time. To handle multiple requests, it spurns multiple threads.

When requests fly fast and numerous and from everywhere, the thread model falls short. Node.js tries to overcome the challenge by providing true asynchornousity. Instead of spawning a new OS thread for each request, Node.js uses one thread. The thread stays idle, however springs to action on events. On each event, the thread takes note, tasks it to one or more processes, then on with another request.

2. Node.js uses an event-driven model. Event-driven is also a cliche, however Node.js gives it some new substance. Best illustrated the point is the article that uses The Doctor’s Office Reception Line Analogy and fast food The Fast Food Restaurant Analogy. Node.js event-driven model is also closely tied with its async feature. Node.js does not allow blocking I/O, that is, it never stops and waits for I/O.

3. Node.js is server side javascript. Sort of. It adopts the syntax and event-driven concept of client side JavaScript, and strives to run "the same script" on both client and server side. However Node is not JavaScript, it is actully written in C, and it runs from command line in unix environment (support for windows is supposedly coming. There has not been a sincere effort). The underlying engine for Node.js is the V8 javascript engine (the same one that runs Google chrome).

4. Node.js is still very new, therefore it has a lot of forseen and unforseen potentials and pitfalls. For one, Node.js is still a very geeky, barebone creature, its library needs to be greatly fleshed out to become a framework of sophistication, upon which developers can readily develop rich web applications. Despite all the buzz and excitement surrounding Node.js, there still lacks high profile web applications built with Node.js.

5. Node is meant for something, but not everything. It is meant for fast and frequent web communications, it is not meant for heavy-duty data access and computation.

"Node has changed our mental image of what a server can be. It doesn't have to be running on a high-performance blade in an air-conditioned co-lo serving millions of requests and gigabytes of data. It can be in your pocket synchronizing your contacts whenever it finds Wi-Fi. It can be caching a web application for faster, local access. It can be a peer-to-peer web server. And it can be a number of things we haven't even thought of yet. "

The secrets of Node's success

by xxxd
Filed under:


No Comments

This site

This Blog



  • MaximumASP