# nanoroutes

> Simple decorator-based routing library, created on top of http module.

Latest version **0.1.0** (published 2022-10-02) · GPL-3.0 license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2022-10-02 |
| First published | 2022-10-02 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 80.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | kotoshii |
| Maintainers | kotoshii |
| Keywords | http, routing, express, router, backend, framework |

## Links

- npm: https://www.npmjs.com/package/nanoroutes
- Repository: https://github.com/kotoshii/nanoroutes
- Homepage: https://github.com/kotoshii/nanoroutes#readme
- Issues: https://github.com/kotoshii/nanoroutes/issues
- npm.io page: https://npm.io/package/nanoroutes

## Dependencies (6)

- [qs](https://npm.io/package/qs.md) ^6.11.0
- [cookie](https://npm.io/package/cookie.md) ^0.5.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [typedi](https://npm.io/package/typedi.md) ^0.10.0
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^6.2.1
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13

## 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.1.0 (latest) — 2022-10-02

## README

# nanoroutes
Simple decorator-based routing library, created on top of [http](https://nodejs.org/api/http.html) module.
Supports most commonly used (if not all) HTTP verbs, async middlewares and Dependency Injection via [typedi](https://www.npmjs.com/package/typedi).

# Instalation
**[nanoroutes](https://www.npmjs.com/package/nanoroutes)** was developed using Node.js version **16.15**. But, although it wasn't tested on older versions, it should work on other versions as well.

To install run

`npm install nanoroutes` or `yarn add nanoroutes`

# Usage
```typescript
import { Controller, Get, createServer, Post, Request, MiddlewareFunction } from 'nanoroutes'

const controllerMiddleware: MiddlewareFunction = (req, res, next) => {
  console.log('controller middleware 1')
  next()
}

const routeMiddlewares: MiddlewareFunction[] = [
  async (req, res, next) => {
    console.log('route middleware 1')
    next()
  },
  (req, res, next) => {
    console.log('route middleware 2')
    next()
  }
]

const globalMiddlewares = [
  async (req, res, next) => {
    console.log('global middleware 1')
    next()
  },
  async (req, res, next) => {
    console.log('global middleware 2')
    next()
  }
]

@Controller('/api', [controllerMiddleware])
class TestController {
  @Get('/error')
  async error() {
    throw new Error('some error')
  }

  @Get('/info')
  async getInfo() {
    return 'some info'
  }

  @Post('/body', routeMiddlewares)
  async getBody(req: Request) {
    return req.body
  }
}

const server = createServer()
server
  .useMiddleware(...globalMiddlewares)
  .listen(8000, () => console.log('started'))
```

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