Skip to content
simple regex router
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md
index.js
package.json

README.md

reg-router

npm version downloads js-standard-style

Just your reg router to match routes based on provided regex.

Usage

var router = require('reg-router')()

router.route(/^\/reset$/, function (req, res, params) {
  res.writeHead(200, 'reset route is hit', { 'content-encoding': 'application/json' })
}

http.createServer(function (req, res) {
  router.match(req, res)
}).listen(8080)

API

router = new Router()

Creates a new instance off reg-router.

router.route(regex, handler)

Register a new route. Handler is generally req, res, params.

router.default(handler)

Defaults to sending back a 404, but you can provide your own default. router.default will do this for you.

router.match(req, res)

Match requests to registered routes. Would usually use when server's fired up.

Related content:

License

MIT

You can’t perform that action at this time.