I'm making a web app which display a HTML table. The app is written in Express and is backed by mongo.
I need to dynamically style different boxes / cells in the table depending on a whole lot of different factors like data comparisons, data types and so on.
Right now, I'm trying to render the json I get from mongo using jade.
But what I need to do is to read the rows from mongo, apply table tags to the fields, basically construct a HTML table and echo it on the page AS-IT-IS.
Meaning, I'll be constructing html using the code and then display it as html, just like the rails html_safe method.
How can I do that with express.js ?
You can just use the res.send()
method for this.
var table = '<table><tr><td>hi!</td></tr></table>';
res.send(table);
If you need to send it in multiple chunks to the browser, you can use nodes res.write()
instead, as res.send()
will end the response.
var table = '<table><tr><td>hi!</td></tr></table>';
res.write(table);