Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A URL router for node.js
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
routes.js Return true if url matched or false if unmatched


A simple url router.

Two methods are provided:

router.route(request, response, urls)

urls should be an array of arrays in the from:

urls = [
    ['/regex', function(request, response){}]

Additionally, if your regex contains capture groups, they will be passed as arguments after request and response to your function. For example:

urls = [
    ['^/media/(.*)$', function(request, response, files){
        /* serve file */

In this case, if the url /media/img/logo.png is fetched, the argument files would be passed to the function as "img/logo.png".


urls should be in the same form as for route. This is used for nesting url lookups. That is all /forum/ urls go to forum.urls and so on. For example:

var router = require('./router');
var forumUrls = require('./forum').urls;
var home = require('./pages').home;

urls = [
    ['^/$', home],
    ['^/forum/.*', router.include(forumUrls)]
Something went wrong with that request. Please try again.