瀟湘沐
2019-02-20 15:19:27
用express實(shí)例化一個(gè)app對(duì)象然后我想將這樣的代碼寫進(jìn)一個(gè)單獨(dú)的js文件,作為一個(gè)模塊,但是會(huì)報(bào)找不到app對(duì)象的錯(cuò)想問下我應(yīng)該怎么模塊化管理自己的接口
2 回答

炎炎設(shè)計(jì)
TA貢獻(xiàn)1808條經(jīng)驗(yàn) 獲得超4個(gè)贊

猛跑小豬
TA貢獻(xiàn)1858條經(jīng)驗(yàn) 獲得超8個(gè)贊
推薦使用對(duì)應(yīng)的route
// invoked for any requests passed to this router
router.use(function(req, res, next) {
// .. some logic here .. like any other middleware
next();
});
// will handle any request that ends in /events
// depends on where the router is "use()'d"
router.get('/events', function(req, res, next) {
// ..
});
添加回答
舉報(bào)
0/150
提交
取消