Neurotic and Probably Misinformed
Introducing npm Teams! Private packages + team management tools.Learn more »

reg-router

1.0.1 • Public • Published

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

Keywords

none

Install

npm i reg-router

DownloadsWeekly Downloads

2

Version

1.0.1

License

MIT

Last publish

Collaborators

  • avatar