how can Export the class and define middleware in typescript
create instance of your class before export.Try some like:
class User {...}const userRoute = new User()export {userRoute}
Updated based in doc of
routing-controllers
according to the github page of that library, the use in express should be like this:
@Controller()export class UserController { @Get("/users") getAll(@Req() request: Request, @Res() response: Response) { return response.send("Hello response!"); }}import "reflect-metadata";import { useExpressServer } from "routing-controllers";let express = require("express"); // or you can import it if you have installed typingslet app = express(); // your created express server// app.use() // you can configure it the way you wantuseExpressServer(app, { // register created express server in routing-controllers controllers: [UserController] // and configure it the way you need (controllers, validation, etc.)});app.listen(3000); // run your express server
take a look at their doc