Closed RaghavendhraK closed 10 years ago
We're using it with express 4, so . . .
I am calling the next method like this. app.get('/', (res, req, next)-> res.render('some_template', some_value); next() ) Is this the rigth way of calling the next using the render method?
If you want to do anything after rendering, you need to pass a callback to the render function; otherwise, express will send the html response right away. Something like this:
app.get('/', function(req, res, next) {
res.render('home.html', { foo: 'bar' }, function(err, html) {
// render takes a callback so you could do whatever you need to do here.
// We report on total latency to datadog and catch strange render exceptions,
// for example, and then call res.send with the html. But you could throw it on
// req and call next if you had other middleware handlers.
res.send(html);
});
});
Yeah I missed this one. Thanks for the reply.:-)
When I call the next() method, It gives the below error message. /project/node_modules/express/lib/response.js:946 if (err) return req.next(err); ^ TypeError: Property 'next' of object GET / HTTP/1.1 host: localhost:4000 user-agent: Mozilla/5.0 (X11; Ubuntu; Linux x8664; rv:31.0) Gecko/20100101 Firefox/31.0 accept: text/html,application/xhtml+xml,application/xml;q=0.9,/_;q=0.8 accept-language: en-US,en;q=0.5 accept-encoding: gzip, deflate cookie: rock_format=json connection: keep-alive if-none-match: W/"a-3175020501" is not a function at fn (/project//node_modules/express/lib/response.js:946:25) at /project/node_modules/hogan-express/hogan-express.js:172:20 at /project/node_modules/hogan-express/hogan-express.js:40:14 at fs.js:266:14 at Object.oncomplete (fs.js:107:15)