@nr-sfly/express-dynamic-routes
v1.3.2
Published
Express router base on files structure
Downloads
21
Readme
Express Dynamic Router
Create a dynamic Express router based on files structure
Usage
Install
npm install @nr-sfly/express-dynamic-routes --save
Usage
import express from 'express';
import {dynamicRouter} from "@nr-sfly/express-dynamic-routes";
const port = 3000;
const app = express();
app.use(express.json());
app.use(dynamicRouter(__dirname))
app.listen(port, () => console.log(`listen port ${port}`));
This folder/file structure
│
├───base
│ ├───index.get.ts
│ ├───health.get.ts
│ └───todos
│ ├───index.get.ts
│ ├───create.post.ts
│ └───:id.get.ts
│
└───app.ts
will transform
| URL | File | Method |
|---------------|-----------------------------|--------|
| / | base/index.get.ts
| GET |
| /health | base/health.get.ts
| GET |
| /todos | base/todos/index.get.ts
| GET |
| /todos/create | base/todos/create.post.ts
| POST |
| /todos/:id | base/todos/:id.ts
| GET |