# troute

> super fast tiny router

Latest version **0.0.6** (published 2013-11-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install troute
pnpm add troute
yarn add troute
bun add troute
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2013-11-03 |
| First published | 2013-06-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Joseph Werle |
| Maintainers | werle |
| Keywords | router, fast, tiny, small, simple |

## Links

- npm: https://www.npmjs.com/package/troute
- Repository: https://github.com/jwerle/troute
- Issues: https://github.com/jwerle/troute/issues
- npm.io page: https://npm.io/package/troute

## Dependencies (1)

- [sregex](https://npm.io/package/sregex.md) *

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 0.0.6 (latest) — 2013-11-03
- 0.0.5 — 2013-06-24
- 0.0.4 — 2013-06-19
- 0.0.3 — 2013-06-18
- 0.0.2 — 2013-06-18
- 0.0.1 — 2013-06-18

## README

troute
======

super fast tiny router

## install

```js
$ npm install troute
```

## usage

using `troute` is super simple

```js
require('http').createServer(troute('GET', '/home', function (req, res) {
  res.end('+1');
})).listen(8000);
```

you can use variable assignment in your route and capture their values in the `req.params` object

```js
require('http').createServer(troute('GET', '/videos/:id', function (req, res) {
	console.log(req.params.id); // '1234'
})).listen(5000);
```

## api

### troute(method, route, fn)

`troute` accepts a valid http method, a string or `RegExp` route, and a function `fn(req, res, next)` as a callback

* `method` - a valid http method
* `route` - a string or `RegExp` for route matching
* `fn` - a callback function when the route is matched

***see [sregex](https://github.com/jwerle/sregex)*** for more information defining string and `RegExp` routes

***example***

```js
require('http').createServer(troute('GET', '/home', function (req, res) {
  res.end('+1');
})).listen(8000);
```

### .get(route, fn)

matches all `GET` requests

* `route` - a string or `RegExp` for route matching
* `fn` - a callback function when the route is matched

***example***

```js
troute.get('/home', home);
```

### .post(route, fn)

matches all `POST` requests

* `route` - a string or `RegExp` for route matching
* `fn` - a callback function when the route is matched

***example***

```js
troute.post('/users', createUser);
```

### .put(route, fn)

matches all `PUT` requests

* `route` - a string or `RegExp` for route matching
* `fn` - a callback function when the route is matched

***example***

```js
troute.put('/videos/:id', editVideo);
```


### .del(route, fn)

matches all `DELETE` requests

* `route` - a string or `RegExp` for route matching
* `fn` - a callback function when the route is matched

***example***

```js
troute.del('/videos/:id', deleteVideo);
```

### .head(route, fn)

matches all `HEAD` requests

* `route` - a string or `RegExp` for route matching
* `fn` - a callback function when the route is matched

***example***

```js
troute.head('/resources', resourcesHead);
```

### .options(route, fn)

matches all `OPTIONS` requests

* `route` - a string or `RegExp` for route matching
* `fn` - a callback function when the route is matched

***example***

```js
troute.options('/videos', videosOptions);
```

## license

MIT

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