node package manager



Simple framework independent routing middleware for node.js.


This was build as a dropin replacement for the routing middleware in express.js.

pfadfinder should do the same, but in a decoupled way so it can be used with other middleware frameworks, too.


http = require 'http'
pfadfinder = require 'pfadfinder'
router = pfadfinder()

router.get '/hello', (req, res) -> res.end 'hello world'
router.get '/hello/:name', (req, res) -> res.end "hello #{}" '/hello/:name', (req, res) -> res.end "post to #{}"

server = http.createServer router.middleware
server.listen 8888

You can find this example and another in the example folder.


pfadfinder can be composed with other middlewares. For example if no route is matched, pfadfinder calls it own next method.

Composer merges an array of middlewares into own middleware. To present a default 404 if a route was not found it is possible to do this:

composer = require 'composer'
router = pfadfinder()
notFound = (req, res) ->
    res.writeHead 404
    res.end 'not found'

composition = composer [router.middleware, notFound]
server = http.createServer composition
server.listen 8888