Tuesday, November 24th, 2009
Node and Djangode Follow-Up
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.
- var dj = require('./djangode');
- var app = dj.makeApp([
- ['^/$', function(req, res) {
- dj.respond(res, 'Homepage');
- }],
- ['^/other$', function(req, res) {
- dj.respond(res, 'Other page');
- }],
- ['^/page/(\\d+)$', function(req, res, page) {
- dj.respond(res, 'Page ' + page);
- }]
- ]);
- dj.serve(app, 8008);
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.





Leave a comment