Reputation: 11
I am fetching data from mongodb using mongoose below code shows the output on web browser.
app.get('/users', function (req, res) {
User.find({}, function (err, docs) {
res.json(docs);
});
});
I need to display this data in HTML format in index.jade inside a table. How to do? please help
Upvotes: 0
Views: 74
Reputation: 122
You need to tell express where your view files are and that you are using jade.
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
Then render the index file with the user data.
app.get('/users', function(req, res, next) {
User.find({}, function (err, docs) {
res.render('index', { users: docs });
}
});
Now inside the index.jade you create a table and iterate over the users.
table
each user in users
tr
td
user.name
Something along those lines.
Check expresses and jades documentation.
http://expressjs.com/4x/api.html#res.render
http://jade-lang.com/reference/iteration/
*edit - I'm assuming your just using express and jade here and not looking to render the json on the front end with a front end framework.
Upvotes: 1