Monday 5 June 2017

What is the purpose of the res.render callback argument in Express 4.0 in Node.js?

What is the purpose of the res.render callback argument?

In which case would one want to use such a callback argument, since a template is already assigned as the first argument?

Here's the code from the documentation:

// 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) {
  // ...
});

I understand the purpose of the first two arguments, but not the last.



via roadtocode

No comments:

Post a Comment