Socket
Socket
Sign inDemoInstall

server-router

Package Overview
Dependencies
Maintainers
4
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

server-router

Server router


Version published
Weekly downloads
30
decreased by-18.92%
Maintainers
4
Weekly downloads
 
Created
Source

server-router stability

npm version build status test coverage downloads js-standard-style

Performant radix-trie router for streaming servers.

Usage

var serverRouter = require('server-router')
var http = require('http')

var router = serverRouter({ default: '/404' })

router.route('GET', '/hello', function (req, res, params) {
  res.end('hello world')
})

router.route('PUT', '/hello/:name', function (req, res, params) {
  res.end('hi there ' + params.name)
})

router.route('', '/404', function (req, res, params) {
  res.status = 404
  res.end('404')
})

http.createServer(router.start()).listen()

API

router = serverRouter(opts)

Create a new router with opts.

router.route(method|[methods], route, function (req, res, params))

Register a new route with an HTTP method name and a routename. Can register multiple handlers by passing an array of method names. params contains matched partials from the route.

router.match(req, res)

Match a route on a router.

handler = router.start()

Return a function that can be passed directly to http.createServer() and calls router.match().

Installation

$ npm install server-router

See Also

  • wayfarer - vanilla radix-trie router
  • nanorouter - client-side radix-trie router

License

MIT

Keywords

FAQs

Package last updated on 28 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc