nnx-express-router-factory
v1.0.1
Published
This is a router factory implementation for [Express](https://www.npmjs.com/package/express). If you using Express, you can use this module for creating routers (and end-points).
Downloads
10
Readme
This is a router factory implementation for Express. If you using Express, you can use this module for creating routers (and end-points).
Quick start
You can install with npm instal
command
$ npm install nnx-express-route-factory
and implement like this (to an Express base project);
import express from 'express';
// import 'nnx-route-factory' module
import nnxExpressRouterFactory from 'nnx-express-router-factory';
const app = express();
// create router config
const routerConfig = [
{
method: nnxExpressRouterFactory.METHOD.GET,
path: 'my/path',
handler: [middlewareFunctiom, myHandlerFunction],
},
{
method: nnxExpressRouterFactory.METHOD.GET,
path: 'my/other-path',
handler: myOtherHandlerFunction,
}
]
// create Express route object
const myRoute = nnxExpressRouterFactory(routerConfig);
// Add route to your Express App
app.use(myRoute);
Reference
Functions
Typedefs
nnxExpressRouterFactory(routerConfig) ⇒ express.Router
Generates express route object.
Kind: global function
| Param | Type | | --- | --- | | routerConfig | Array.<EndPointConfig> |
nnxExpressRouterFactory.METHOD : enum
Kind: static enum of nnxExpressRouterFactory Read only: true Properties
| Name | Type | Default | | --- | --- | --- | | ALL | string | "all" | | GET | string | "get" | | HEAD | string | "head" | | POST | string | "post" | | PUT | string | "put" | | DELETE | string | "delete" | | CONNECT | string | "connect" | | OPTION | string | "option" | | TRACE | string | "trace" | | PATCH | string | "patch" |
EndPointConfig : Object
Router end-point config data.
Kind: global typedef Properties
| Name | Type | | --- | --- | | method | METHOD | | path | String | | handler | function | Array.<function()> |