# express-route-auto

> auto express route

Latest version **2.0.6** (published 2017-05-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-route-auto
pnpm add express-route-auto
yarn add express-route-auto
bun add express-route-auto
```

## 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 | 2.0.6 |
| Published | 2017-05-25 |
| First published | 2016-10-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | ctyloading |
| Maintainers | ctyloading |
| Keywords | express, route |

## Links

- npm: https://www.npmjs.com/package/express-route-auto
- Repository: https://github.com/looading/express-route-auto
- Homepage: https://github.com/looading/express-route-auto#readme
- Issues: https://github.com/looading/express-route-auto/issues
- npm.io page: https://npm.io/package/express-route-auto

## Dependencies (6)

- [lodash](https://npm.io/package/lodash.md) ^4.17.2
- [express](https://npm.io/package/express.md) ^4.14.0
- [@types/node](https://npm.io/package/@types/node.md) ^7.0.22
- [@types/debug](https://npm.io/package/@types/debug.md) 0.0.29
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.64
- [@types/express](https://npm.io/package/@types/express.md) ^4.0.35

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

- 2.0.6 (latest) — 2017-05-25
- 2.0.5 — 2017-05-25
- 2.0.4 — 2017-05-23
- 2.0.3 — 2017-05-23
- 2.0.2 — 2017-05-23
- 2.0.1 — 2017-05-23
- 2.0.0 — 2017-05-23
- 1.2.3 — 2016-12-18
- 1.2.2 — 2016-12-12
- 1.2.1 — 2016-12-12
- 1.2.0 — 2016-12-11
- 1.1.4 — 2016-12-04
- 1.1.3 — 2016-12-02
- 1.1.2 — 2016-12-01
- 1.1.1 — 2016-12-01
- … 19 more at https://npm.io/package/express-route-auto/versions

## README

[![Build Status](https://travis-ci.org/looading/express-route-auto.svg?branch=master)](https://travis-ci.org/looading/express-route-auto)
[![npm](https://img.shields.io/npm/v/express-route-auto.svg?maxAge=2592000)](https://www.npmjs.com/package/express-route-auto)
[![npm](https://img.shields.io/npm/dm/express-route-auto.svg?maxAge=2592000)](https://www.npmjs.com/package/express-route-auto)


## express-route-auto
用于express路由的自动加载

初步想法是为了便于 后端服务的开发

推荐用Typescript

## install

```bash
npm install express-route-auto --save
```

## setup
``` ts
import  * as express from "express";
import * as util from "util";
import { Generate } from "express-route-auto";


const port = 3000;


let app = express();

app.get('/123/', (req, res, next) => {
  next()
})

let generate = new Generate({
  // routeDir 是必须的， 是controller的文件地址（相对于根目录））
  routeDir: 'controller',
  // APP_PATH 也是必须的，是模块获取到根目录路径
  APP_PATH: __dirname,
  /**
  * 为里每一个Controller增加props 挂载到this上， 比如数据库的Model -> this.User.add(...)
  * props: {
  *   User: Model.User
  * }
  */
  props: {
    Name: 'looading'
  }
});
// let routes = generate()
app.use(generate.init());

app.listen(port, () => {
  console.info(`server is running on port: ${port}`);
})
```

## Controller
```js
import { Action } from "express-route-auto";

class Index extends Action {
  params = {
    get: ['id']
  }
  constructor() {
    super();
  }
  post = (req, res, next) => {
    res.send('this is / ::post!');
  }
	get = (req, res, next) => {
    let { id } = req.params
		res.json({
      id,
      context: 'this is / ::get!'
    });
	}
  delete = (req, res, next) => {
    res.send('this is delete')
  }
}

module.exports = new Index();


```

## 路由目录结构

```js
- controller
	- user				
		- index.js		=>	/user/
		- show.js			=> /user/show
    - info        // 空目录不会成为路由
    — detail
      - index.js  => /user/detail
	- index.js			=> /
```

### continue
按照上述的配置基本就能跑起来了
详细的可以查看demo文件里的代码
由于是基于自己项目的，目前还没有扩展开来。

### feature

...

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