# couch-routes

> Clean and scalable upgrade to express. Eliminate route file with decorators for controllers and dependency resolution.

Latest version **1.5.9** (published 2024-08-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install couch-routes
pnpm add couch-routes
yarn add couch-routes
bun add couch-routes
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.9 |
| Published | 2024-08-03 |
| First published | 2021-11-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 179.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Darrell Couch |
| Maintainers | call_me_couch |
| Keywords | express, node, node.js, dependency, injection, dependency injection, typescript, decorators, routing, express routing, class based express |

## Links

- npm: https://www.npmjs.com/package/couch-routes
- Repository: https://github.com/darrellncouch/couch-routes
- Homepage: https://github.com/darrellncouch/couch-routes#readme
- Issues: https://github.com/darrellncouch/couch-routes/issues
- npm.io page: https://npm.io/package/couch-routes

## Dependencies (2)

- [express](https://npm.io/package/express.md) ^4.17.1
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.5.9 (latest) — 2024-08-03
- 1.5.8 — 2024-08-03
- 1.5.7 — 2024-08-03
- 1.5.6 — 2024-08-03
- 1.5.5 — 2024-08-03
- 1.5.4 — 2024-08-03
- 1.5.3 — 2024-08-03
- 1.5.2 — 2023-11-29
- 1.5.1 — 2023-11-29
- 1.5.0 — 2023-11-29
- 1.4.0 — 2023-11-29
- 1.3.0 — 2023-11-26
- 1.2.2 — 2022-02-07
- 1.2.1 — 2022-02-06
- 1.2.0 — 2022-02-06
- … 15 more at https://npm.io/package/couch-routes/versions

## README

# couch-routes

## What is this?

couch-routes is a simple and light-weight package built to simplify routing and dependencies </br> through a typescript class based approch to express.

## Why use couch-routes

The intention of couch-routes is to clean up the common file structure of an express application while </br> making it more intuitive and familliar to the common structure and feel of web frameworks throughout </br> different languages. This packages takes consideration from Dot Net as well as Angular, giving a familliar </br> routing and dependency injection experience.

## Installation

`npm i couch-routes --save`

## tsconfig.json
"compilerOptions": { </br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"experimentalDecorators": true,</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"emitDecoratorMetadata": true,</br>
}


## Usage

app.ts
```
import * as router from "couch-routes";
import controllers from "./controllers" //Array of controller classes

const app = express();

router.initialize(app, controllers);
```

Controllers
```
import * as express from "express";
import { MyService } from "../services/myService"'
import {Controller, Get, Put, Post, Delete } from "couch-routes/decorators";

@Controller("/user")
export default class UserController {

    constructor(private readonly myService: MyService) {}

    @Get("/:id")
    public async getUserById(req: express.Request, res: express.Response) {
        const id = req.query.id;
        res.send(await this.myService.getUserById(id));
    }

    @Get()
    public async getAll(req: express.Request, res: express.Response) {
        res.send(await this.myService.getAll());
    }

    @Delete("/:id")
    public async deleteUser(req: express.Request, res: express.Response) {
        res.send(await this.myService.delete(req.query.id))
    }

    @Post()
    public async CreateUser(req: express.Request, res: express.Response) {
        res.send(await this.myService.add(req.body.user));
    }

    @Put("/:id")
    public async deleteUser(req: express.Request, res: express.Response) {
        res.send(await this.myService.update(req.query.id, req.body.user))
    }

}
```

Dependency injection for non controllers
```
import { Service } from "couch-routes/decorators"
import { UserData } from "../data/userData";

@Service()
export default class MyService {

    constructor(private readonly userData: UserData) {

    }

    public async getUserById(id: number) {
        return await this.userData.getUser(id);
    }
}
```

## Options

Controller(routePrefix: string)</br>
Get(route: string)</br>
Put(route: string)</br>
Post(route: string)</br>
Delete(route: string)</br>

*all of the above default with "/" if nothing is passed*

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