How can I send some HTML, render a view, then send more HTML in Express+Node.js?


I’m using Node.js+Express, and I’ve come across a case where I need to send some HTML, render a view, then send some more HTML in the one response.

The flow would be:

res.send('some html');
res.render('module.html', {});
res.send('more html');

Now I know that res.render supports a callback, so I could do:

res.render('module.html', {}, function () {
res.send('more html');

But res.send() doesn't appear to. Is there a way to achieve this?

Problem courtesy of: nkunicki


Like Raynos Said I would recommend looking into view partials. This video from Author TJ explains the basics.

As a sidenote res.send send a full response and then closes the connection. You can not be using that if you want to send more text after that.

enter image description here

So you have to use node.js native res.write to do what you want instead.

Solution courtesy of: Alfred

View additional discussion.