router
Simple middleware-style router
Installation
$ npm install router
API
var Router = require('router')
This module is currently an extracted version from the Express 4.x project,
but with the main change being it can be used with a plain http.createServer
object or something like connect
by removing Express-specific API calls.
Documentation is forthcoming, but the Express 4.x documentation can be found
at http://expressjs.com/4x/api.html#router
Example
Simple example of using the router independently of any framework.
var finalhandler = require('finalhandler')
var http = require('http')
var Router = require('router')
var router = new Router()
router.get('/', function (req, res) {
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
res.end('hello, world!')
})
var server = http.createServer(app)
server.listen(3000, function onListening() {
console.log('http server listening on port ' + this.address().port)
})
function app(req, res) {
router(req, res, finalhandler(req, res))
}
Testing
$ npm test
License
MIT