Activate your free membership today | Log-in

Tuesday, November 24th, 2009

Node and Djangode Follow-Up

Category: Node, Server

>

Simon Willison's Talk last week on Node generated a healthy dose of post-conference buzz, and he's followed up with a blog post on Node and his higher-level API for Node, Djangode.

Node’s core APIs are pretty low level—it has HTTP client and server libraries, DNS handling, asynchronous file I/O etc, but it doesn’t give you much in the way of high level web framework APIs. Unsurprisingly, this has lead to a cambrian explosion of lightweight web frameworks based on top of Node—the projects using node page lists a bunch of them. Rolling a framework is a great way of learning a low-level API, so I’ve thrown together my own—djangode—which brings Django’s regex-based URL handling to Node along with a few handy utility functions.

JAVASCRIPT:
  1.  
  2. var dj = require('./djangode');
  3.  
  4. var app = dj.makeApp([
  5.   ['^/$', function(req, res) {
  6.     dj.respond(res, 'Homepage');
  7.   }],
  8.   ['^/other$', function(req, res) {
  9.     dj.respond(res, 'Other page');
  10.   }],
  11.   ['^/page/(\d+)$', function(req, res, page) {
  12.     dj.respond(res, 'Page ' + page);
  13.   }]
  14. ]);
  15. dj.serve(app, 8008);
  16.  

Pretty simple, and gets a whole lot more interesting when he shows how to build a simple Comet server with this API. He also covers database access, where there's a good fit between server-side Javascript and the NOSQL servers that speak HTTP and JSON.

His article also provides a nice overview of Node itself, along with some straightforward install instructions.

At first glance, Node looks like yet another take on the idea of server-side JavaScript, but it’s a lot more interesting than that. It builds on JavaScript’s excellent support for event-based programming and uses it to create something that truly plays to the strengths of the language.

Node describes itself as “evented I/O for V8 javascript”. It’s a toolkit for writing extremely high performance non-blocking event driven network servers in JavaScript. Think similar to Twisted or EventMachine but for JavaScript instead of Python or Ruby.

Related Content:

Posted by Michael Mahemoff at 9:53 am
1 Comment

+++--
3.9 rating from 28 votes

1 Comment »

Comments feed TrackBack URI

Interesting article

Comment by Aphrodisiac — January 15, 2010

Leave a comment

You must be logged in to post a comment.