使用next()传递variables

在node.js中,我有function,在任何行动之前检查是否一切正常在请求的开始(validationJSON等)。 几乎一切正常,但我有一个问题。 我现在不使用next()来传递对象引用。

调用我正在使用的检查function。

app.all('/:action', frontendProcessor.checkSession()); 

在这段代码的中间,我使用next()

 frontendProcessor.checkSession = function(){ return function(req, res, next) { var inputJson = req.body.JSONVAR || false, action = req.params.action; // validation frontendProcessor.validateJSON(inputJson, afterValidation); function afterValidation(err, inputData){ if(err) { global.consoleLog(err); res.send(fail); }else{ if(action == 'login' ){ console.log(inputData); next(inputData); //<< here, how to pass inputData thru next }else{ mUsers.checkSessionId(email, sessionId, process); }; }; }; function process(response) { if(!response){ global.consoleLog("Security Error: Bad session Id."); var response = JSON.stringify(badSession); res.send(response); }else{ global.consoleLog('Security: session ok! next'); next(inputData); }; }; }; }; 

next()不应该传递数据,因为它只是用来调用下一个请求处理程序,而不是一个特定的请求处理程序。 Nirk的评论是正确的,你应该将你的数据附加到req对象,并在需要时从那里读取它。