Node.js
I’ve heard about Node.js before, but I didn’t understand what it was about. The website says “Evented I/O in javascript”. What does that mean? I had no clue. And if you scroll down, there’s an example of a webserver in javascript. What does that have to do with evented i/o? Why doesn’t the site say “server side javascript” instead of “evented i/o”? I still didn’t know, and so I didn’t care much.
Also I had a day job and it was hard to keep up with what’s going on. Specially keeping up with languages/platforms, and things that require a good chunk of time to try out and evaluate. So I ended up not really knowing anything about what the fuss is about.
Until yesterday, when I saw a comment on hacker news, where someone mentioned how Node.js allowed his site to handle very heavy traffic without any problems.
Now that’s weird. What does any of the above have to do with handling heavy traffic? I didn’t know, but it made me curious.
I went to nodejs.org and started looking for more information. I ended up watching the tech talk given by its author, and everything made sense.
I recommend you watch it too, it’s very fun and informative.
Basically, it’s server side javascript, so it allows you to write web apps entirely in javascript (a single js file can be a good starting point). All operations that normally block (that is, I/O) are done asynchronously, using events and event handlers. There’s only one thread, one stack. To handle a request, you specify a callback for the “incoming request” event. Want to serve a file? You have to do it with an event. You tell it to start loading the file, and you give it a callback function that gets executed when the file is loaded. It’s completely asynchronous; it never blocks.
I probably made it sound somewhat dull, and you might be wondering “why bother at all?”. Just go ahead and watch the video, it’s really good. He talks a lot about the current models for handling I/O and why they all fail, and many of the ideas behind the project, and it should answer most of the “why bother?” questions.