What is Node.js?

We have been hearing a lot about how good Node.js is. Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. It is one of the most popular platform for building web server applications.

In general, Node.js is:

  • A JavaScript runtime built on Chrome's V8 JavaScript engine;
  • A command-line tool that can be run as a regular web server and lets one run JavaScript programs;
  • Very good when you need to do several things at the same time.
  • An event-based and all the wonderful Ajax-like stuff can be done on the server side;
  • Let's share code between the frontend and the backend.
  • Talk to database and have the I/O controls;

For more about Node.js and its Advantages & Disadvantages.

When to use Node.js

My feeling is that Node.js is especially suited for applications where you would like to maintain a persistent connection from the browser back to the server. Using a technique known as "long-polling", you can write an application that sends updates to the user in real time. Doing long polling on many of the web's giants, like Ruby on Rails or Django, would create immense load on the server, because each active client eats up one server process. This situation amounts to a tarpit attack. When you use something like Node.js, the server has no need of maintaining separate threads for each open connection.

This means you can create a browser-based chat application in Node.js that takes almost no system resources to serve a great many clients. Any time you want to do this sort of long-polling, Node.js is a great option.

It's worth mentioning that Ruby and Python both have tools to do this sort of thing (eventmachine and twisted, respectively), but that Node.js does it exceptionally well, and from the ground up. JavaScript is exceptionally well situated to a callback-based concurrency model, and it excels here. Also, being able to serialize and deserialize with JSON native to both the client and the server is pretty nifty.

In addition, it's worth pointing out that Node.js is also great for situations in which you'll be reusing a lot of code across the client/server gap. A lot of folks are suggesting this might be the future of web development.

References & Resources

  • N/A