url.format (http://nodejs.org/api/url.html) might make this a bit nicer.