# express-dir-router

> Manage express routes by directory.

Latest version **1.0.4** (published 2019-03-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-dir-router
pnpm add express-dir-router
yarn add express-dir-router
bun add express-dir-router
```

## 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 | 1.0.4 |
| Published | 2019-03-18 |
| First published | 2019-03-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Zirui Wang |
| Maintainers | zirui |

## Links

- npm: https://www.npmjs.com/package/express-dir-router
- Repository: https://github.com/zirui-wang/express-dir-router
- Homepage: https://github.com/zirui-wang/express-dir-router#readme
- Issues: https://github.com/zirui-wang/express-dir-router/issues
- npm.io page: https://npm.io/package/express-dir-router

## Recent versions

- 1.0.4 (latest) — 2019-03-18
- 1.0.3 — 2019-03-15
- 1.0.2 — 2019-03-14
- 1.0.1 — 2019-03-14
- 1.0.0 — 2019-03-14

## README

# Express Dir Router

Manage express routes by directory. Now support `GET`, `POST`, `PUT`, `DELETE`, and `PUT`.

## Install

```sh
$ npm install express-dir-router
```

## Usage

Let's say you want to have a route like below:

```http
GET /api/v1/greeting
```

Under `routes`, You can create directory structure like below:

```html
routes
    |---v1
        |---greeting.js
```

Configuration is easy: just pass `app` and `root` path. You can also pass `prefix` as well as `filter`:

```js
// index.js

const app = require('express')();
const expressDirRouter = require('express-dir-router');

expressDirRouter(app, __dirname, {
  prefix: '/api', // You can also use an 'api' directory between 'routes' and 'v1'.
  filter: filename => filename !== 'index.js'
});
```

The format of the route file is like below. You should return an object that contains `method`, `url`, and `handler`. Just like the principle in `Express`, you can pass an array of functions to `handler`.

```js
// greeting.js

module.exports = app => {
  return {
    method: 'get',
    url: '/greeting',
    handler: (req, res) => {
      res.send('Hello!');
    }
  };
};
```

## Examples

To see `routing` and `testing` working under `express-dir-router`, please see [examples](./examples/index.js).

## License

MIT

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