在Node.Js Express中,“res.render”是否结束http请求?

所以,只有在确定一切已经完成的时候才做“res.render”,对吗? 因为它结束了请求并且射出一个网页。

如果你没有提供res.render(view[, options[, fn]])的callbackres.render(view[, options[, fn]])它会自动给出一个200 HTTP状态和内容types的响应:text / html

 res.render('view', {}, function() { while (true); // should block }); 

res.render(view [,options [,fn]])

使用给定的选项和可选的callback函数fn来渲染视图。 当一个callback函数被给出时,响应将不会自动进行,否则会给出200和text / html的响应。

express.js指南

使用当前的github主提交 ,这是lib / view.js中的res.render :

  /** * Render `view` with the given `options` and optional callback `fn`. * When a callback function is given a response will _not_ be made * automatically, however otherwise a response of _200_ and _text/html_ is given. * * Options: * * - `scope` Template evaluation context (the value of `this`) * - `debug` Output debugging information * - `status` Response status code * * @param {String} view * @param {Object|Function} options or callback function * @param {Function} fn * @api public */ res.render = function(view, opts, fn, parent, sub){ // support callback function as second arg if ('function' == typeof opts) { fn = opts, opts = null; } try { return this._render(view, opts, fn, parent, sub); } catch (err) { // callback given if (fn) { fn(err); // unwind to root call to prevent // several next(err) calls } else if (sub) { throw err; // root template, next(err) } else { this.req.next(err); } } };