The amazing adventures of Doug Hughes

Recently, Ive been dipping my toes into languages and technologies I might not previously have. For the last ten years or so ColdFusion has been my bread and butter. Yes, Ive tinkered with other languages like Groovy, but now Im trying to make a more concerted effort to learn more about things I otherwise might not.

Recently Ive been teaching myself a little Ruby and Rails. A local buddy of mine, Bucky Schwarz brought the The Raleigh-area Ruby Brigade to my attention. Last night I attended one of their meetings anticipating learning more about Ruby. However, the topic was not on Ruby, but on NodeJS. The talk was given by Aaron Heckmann.

I recently heard about some developments around JavaScript based servers. Some people are making use of them because they can apparently handle insane loads. Ive heard of some applications handling thousands of connections a second. Last week I tried to Google around and see what I could find, with no luck. So, imagine my surprise when the Ruby meetup topic was about NodeJS, a JavaScript server.

NodeJS is the brainchild of Ryan Dahl and makes use of Googles open source V8 JavaScript engine. Because of this, NodeJS benefits from the recent competition between Firefox, Google, IE, and Opera on JavaScript engine performance. In other words, NodeJS is very fast.

Installing NodeJS was very simple for me, since Im on OS X. I cant say it will be quite that simple for those in the Windows world since you have to download and build the source code. This was as simple as running ./configure, make, make install. Once NodeJS was installed I was able to run a couple of simple sample applications without any problems.

Much to my surprise, I was able to make small changes to these sample applications because I know JavaScript! I was able to take the HTTP hello world application and change it slightly. The same was true for the network socket sample. Cool!

My initial impression with both of these samples were two-fold:

Wow, that starts up fast! For the simple hello world-style applications there was literally no wait to start NodeJS.

The basic sytax was simple and easy to read. All you need to do to start listening for HTTP requests is this:

var http = require('http');
http.createServer(function (req, res) {}

Now, there are some challenges with Node. In particular, its intended to be pretty low-level. Those of us more comfortable working with higher-level languages might find Node, perhaps, a bit cumbersome.

In the example above, once you start node running this application, you can hit this application at http://localhost:3000. The default request will redirect you to /hello/world. You can also go to /goodbye/world.

The Express module has a range of other features for routing requests, rendering views, and more. Frankly, I havent taken it much beyond whats in this article yet.

Despite the relative youth of the NodeJS project, it seems to me like theres a lot of energy and excitement behind it. You only need to look at the Module list to realize there are a lot of people working very hard on this project. Just to highlight a few, there are modules to connect to various databases, including MySQL and MongoDB, and many others. There are also modules for logging, templating, testing, and much, much more.