In Node.Js Express, does res.render complete an HTTP request?

So, only "res.render" when you are sure that everything is over, right? Because it ends the request and removes the web page.

+8
javascript express
source share
2 answers

If you do not provide a res.render(view[, options[, fn]]) , it will automatically return a response with 200 HTTP status and content type: text / html

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

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

Display a view with the given parameters and optional fn callback. When a callback function is specified, the answer will not be executed automatically, however, otherwise 200 and text / html will be answered.

express.js manual

+11
source

With the current github master commit , this is res.render in lib / view.js :

  /** * 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); } } }; 
+4
source

All Articles