Express: How to pass app-instance to routes from a different file?

后端 未结 8 1083
误落风尘
误落风尘 2020-11-29 16:34

I want to split up my routes into different files, where one file contains all routes and the other one the corresponding actions. I currently have a solution to achieve thi

8条回答
  •  余生分开走
    2020-11-29 16:50

    Or just do that:

    var app = req.app
    

    inside the Middleware you are using for these routes. Like that:

    router.use( (req,res,next) => {
        app = req.app;
        next();
    });
    

提交回复
热议问题