//在routes.js
中test = require('test');
app.get('/test', function(req, res) {
test.first(
req,res,
test.second,
'info'
);
});
//在test.js
中exports.first= function(req, res, next, inf){
req.test= inf;
console.log(inf); //info
next();
};
exports.second= function(req, res, next){
console.log(req); //undefined
res.jsonp(req.test);//error :s
};
这是来自how to call a controller with express routes and include a defined parameter
的后续问题答案 0 :(得分:4)
假设您在next();
中呼叫test.first()
,则表示您未向test.second()
传递任何参数。因此,对于您当前的设置,您需要在next(req, res);
中test.first()
代替。