# earf

> Express auto routing

Latest version **2.0.3** (published 2023-03-23) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2023-03-23 |
| First published | 2021-12-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | fredfung9527 |
| Keywords | express, auto, routing, typescript |

## Links

- npm: https://www.npmjs.com/package/earf
- Repository: https://gitlab.com/fredFung9527/express-auto-routing
- Homepage: https://gitlab.com/fredFung9527/express-auto-routing#readme
- Issues: https://gitlab.com/fredFung9527/express-auto-routing/issues
- npm.io page: https://npm.io/package/earf

## 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

- 2.0.3 (latest) — 2023-03-23
- 2.0.2 — 2023-03-14
- 2.0.1 — 2023-03-14
- 2.0.0 — 2023-03-14
- 1.0.13 — 2022-08-09
- 1.0.12 — 2022-04-20
- 1.0.11 — 2022-04-13
- 1.0.10 — 2022-04-13
- 1.0.9 — 2022-02-11
- 1.0.8 — 2022-02-11
- 1.0.7 — 2022-02-11
- 1.0.6 — 2022-01-05
- 1.0.5 — 2021-12-20
- 1.0.4 — 2021-12-17
- 1.0.3 — 2021-12-17
- … 3 more at https://npm.io/package/earf/versions

## README

### Features
- Register routes automatically
- Can set up base path
- Middleware shortcuts

### Download
`yarn add earf`

### Usage
#### In `./app.ts`
```
import express from 'express'
import autoRouting from 'earf'
import { notFoundHandler, errorHandler } from './middlewares/error'
import { testMiddleware } from './middlewares/testMiddleware'

const app = express()
autoRouting(app, {
  folderPath: resolve(__dirname, './routes'), // optional; default value is './routes'
  basePath: '/', // optional; default value is '/'
  callBack: (app) => { // optional
    app.use(notFoundHandler)
    app.use(errorHandler)
  }, 
  middlewareMapping: { // optional; common middlewares for future use
    testMiddleware
  }
})
```
#### For each `.ts` file in `./routes/`, whose name is in ['all' | 'get' | 'post' | 'patch' | 'delete']
```
import { MyRoute } from './../index'

export const route: MyRoute<any, any, any> = {
  handler: (req, res) => {
    console.log('aaaaaaaaaa')
    res.json('bbbbbbbbbb')
  }
}
```

### Others
Dynamic routing: name the file with prefix `_`

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