node package manager
Easy collaboration. Discover, share, and reuse code in your team. Create a free org »


course Flattr this!experimental

A framework-independent express-like router.



router = require('course')()

Creates a new router.

router[method]([urlPattern], middlewares...)

Adds a new middleware to the router. method is an HTTP verb, such as get, post or put, to filter requests by the request method used.

The first argument may optionally be a URL pattern or regular expression to match URLs against. Each argument after the URL is an express-style middleware function with the signature (req, res, next).

router.any([urlPattern], middlewares...)

Same as above, however without filtering by request method.


var db     = require('some-database')
var course = require('course')
var http   = require('http')
var router = course()
var server = http.createServer(function(req, res) {
  router(req, res, function(err) {
    if (err) return res.end(err.message)
router.all(function(req, res, next) {
  // do something on every request... 
// pass in URL filters, and multiple 
// middlewares 
  , getUserData
  , loadHomeView
  , render
function getUserData(req, res, next) {
  db.getUser(function(err, user) {
    if (err) return next(err)
    req.user = user
function loadHomeView(req, res, next) {
  req.view = require('./views/home')
function render(req, res, next) {
    user: req.user
// Or capture URL paths: 
router.get('/user/:username/*', function(req, res, next) {
  var name = this.username
  var page = this[1]


MIT. See for details.