Tag: 接下来

Nodejs和连接“下一个”function

看来,如果我想要移动到Nodejs中的“下一个”function(通常可能是Javascript),我不能将parameter passing给下一个函数。 这是我的意思: app.get('/webpage', SomeFunction, NextFunction); function SomeFunction (req, res, next) { // Do things next(); } function NextFunction (req, res) { // Do other things } 现在,如果在SomeFunction我要说next(req, res); 它似乎没有工作。 它永远不会去的方法。 显然我不能直接传递参数…但是我的问题是为什么? 下一个函数如何知道使用哪个参数? 是因为它们被命名为相同还是自动传递第一个和第二个参数? 如果NextFunction使用blah, bleet而不是req, res会继续工作吗?

在expressjs中使用next()将variables传递给下一个中间件

那么我的问题是我想通过一些variables从第一个中间件到另一个中间件,我尝试这样做,但有req.somevariable是一个给定的'未定义'。 //app.js .. app.get('/someurl/',middleware1,middleware2) … ////middleware1 … some conditions … res.somevariable = variable1; next(); … ////middleware2 … some conditions … variable = req.somevariable; … 谢谢回答。