在Express中间件中,应该有三个参数:请求、响应和下一个处理程序(request, response, next)。然而,在我从一本书中复制的代码中的第二个中间件中,只使用了请求和响应(request, response)。这是什么原因?next是否是可选的?
var express = require("express");
var http = require("http");
var app = express();
app.use(function(request, response, next) {
console.log("In comes a " + request.method + " to " + request.url);
next();
});
app.use(function(request, response) {
response.writeHead(200, { "Content-Type": "text/plain" });
response.end("Hello, world!");
});
http.createServer(app).listen(3000);