1.1.3 • Published 3 years ago
@peu77/expresswrapper v1.1.3
ExpressWrapper
Simple construct for an express application.
Installation
With NPM
npm i @peu77/expresswrapper
With Yarn
yarn add @peu77/expresswrapper
You need to create a service and a controller
Imports
import {
Controller,
initControllers,
RouteType,
Service,
generateListener,
DependencyImpl
} from '@peu77/expresswrapper';
Basic service
const service: Service = {
listeners: [
generateListener(RouteType.POST, "test", (data: any) => {
return {
success: true,
message: "finished",
status: 200,
data: {}
}
})
]
}
Basic controller which use the service
const controller: Controller = {
prefix: "/api",
service: service,
routes: [
{
path: "test",
type: RouteType.POST,
guards: [],
dependencies: []
}
]
}
If you have a controller you can use the initControllers function
const app = express();
app.listen(3000, () => {
initControllers(app, [controller]);
})