# my-express-auto-router

> 自动挂载路由

Latest version **1.0.0** (published 2018-03-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install my-express-auto-router
pnpm add my-express-auto-router
yarn add my-express-auto-router
bun add my-express-auto-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.0 |
| Published | 2018-03-03 |
| First published | 2018-03-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | litinghong |
| Maintainers | litinghong |

## Links

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

## Recent versions

- 1.0.0 (latest) — 2018-03-03

## README

# my-express-auto-router一个用于自动挂再后端路由的包，减少手动写路由的麻烦，还能有效防止路由重复的问题
### 使用方式 

> 1、安装my-express-auto-router``` npm i my-express-auto-router ```
> 
> 2、在代码中引用包

    const autorouter = require('my-express-auto-router');
    const router = express.Router();
    app.use(autorouter(router, __dirname, ['routes']));//第一个参数传router,第一个参数传当前文件路径，第三个参数传需要挂在的路由的根目录
    
>    
>3、说明
>
> ![enter description here][1]
  
 如上图我的routes的目录是这样，那么后端自动把index.js映射到路由/、users.js映射到/users路由，inner映射/inner/xxx,注意index文件名和目录名都不会加入到路由的路径上，同时根目录routes也不会被加入到路由路径。
  打开文件users.js,代码如下
 ![enter description here][2]
 
 可以看到users引出了两个方法index和other,以及一个methodMap。
 这个文件会被后端挂载在路由/users/other和/users,因为index方法会被忽略掉路径名。然后/users/other路由get和post请求都可以而/users只能get请求，这里和mathodMap刚好对应上


  [1]: https://github.com/lth707/express-auto-router/blob/master/image/dir.png "dir.png"
  [2]: https://github.com/lth707/express-auto-router/blob/master/image/users.png "users.png"

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