# tiny-route

> Tiniest HTTP routing library

Latest version **2.1.2** (published 2016-01-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install tiny-route
pnpm add tiny-route
yarn add tiny-route
bun add tiny-route
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.2 |
| Published | 2016-01-02 |
| First published | 2013-06-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Dominic Tarr |
| Maintainers | dominictarr |

## Links

- npm: https://www.npmjs.com/package/tiny-route
- Repository: https://github.com/dominictarr/tiny-route
- Issues: https://github.com/dominictarr/tiny-route/issues
- npm.io page: https://npm.io/package/tiny-route

## Recent versions

- 2.1.2 (latest) — 2016-01-02
- 2.1.1 — 2014-01-04
- 2.1.0 — 2013-07-11
- 2.0.0 — 2013-06-19
- 1.1.0 — 2013-06-14
- 1.0.1 — 2013-06-10
- 1.0.0 — 2013-06-04

## README

# tiny-route

Tiniest routing library.

Routes on a regular expression or a string and calls a handler.
`route(rx, handler(req, res, next))`

# example

``` js
var Stack = require('stack')
var http  = require('http')
var route = require('tiny-route')

http.createServer(Stack(
  route(/\/users/(\w+)/, function (req, res, next) {
    console.log('accessed user', req.params)
    req.end('hello', req.params[0])
    //and so on.
  }),
  route('/index.html', function (req, res) {
    res.end('<!DOCTYPE html><h1>Hello World!</h1>')
  })
))
```

you can also use `tiny-route` to mount a middleware on a path.

``` js
http.createServer(Stack(
  route('/stuff/', Stack(
    route(/\/users/(\w+)/, function (req, res, next) {
      console.log('accessed user', req.params)
      req.end('hello', req.params[0])
      //and so on.
    }),
    route('/index.html', function (req, res) {
      res.end('<!DOCTYPE html><h1>Hello World!</h1>')
    })
  ))
))
```

Now you access `/users/foo` as `/stuff/users/foo`,
this works because tiny-route removes the prefix of the match from `req.url`

## License

MIT

---
_Source: https://npm.io/package/tiny-route · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
