Node.js中Express 4.0的res.rendercallback参数的目的是什么?

res.rendercallback参数的目的是什么?

在这种情况下,我们想使用这样一个callback参数,因为模板已经被指定为第一个参数?

以下是文档中的代码:

 // send the rendered view to the client res.render('index'); // if a callback is specified, the rendered HTML string has to be sent explicitly res.render('index', function(err, html) { res.send(html); }); // pass a local variable to the view res.render('user', { name: 'Tobi' }, function(err, html) { // ... }); 

我理解前两个论点的目的,但不是最后一个。

通过callback,您可以在发送之前拦截呈现的模板。 在发送给客户端之前,您可能需要将其缩小或进行其他修改。

从文档:

如果提供,该方法返回可能的错误和呈现的string,但不执行自动响应。