谁提供了 Express 中间件中的 next() 功能?

Who provides the next() function in Express middleware?

我对 next() 在 Node.js 和 Express 中间件中的工作方式感到困惑。

还有一些关于中间件工作的其他问题,for example here,但我正在寻找不同的答案。

困扰我的主要问题是谁提供了next()功能?

例如,在我的标准生成的 express 应用程序中,我得到了以下代码:

// catch 404 and forward to error handler
app.use(function(req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
});

但是谁调用了这个函数,它提供的 next() 的性质是什么?我怎么知道 next() 会是什么样子?我不知道 next() 是做什么的。

An Express application is essentially a series of middleware calls.

Middleware is a function with access to the request object (req), the response object (res), and the next middleware in line in the request-response cycle of an Express application, commonly denoted by a variable named next.

如上所写,Expressjs提供了下一个回调函数。 Next只是调用流程中下一个中间件的一种方式。

有关许多示例,请参阅 Express 的 Using middleware