I want to display the mongodb data in the form of table in html with node.js, express.js and angular.js.
What I am doing now is something like this
route.js
app.get('/superhero', function(req, res) {
superhero.superhero_list(req,res);
res.sendfile('./public/superhero.html');
});
superhero.js
var express = require ('express')
var rootRequire = require('root-require');
var bodyParser = require('body-parser');
var superheroSchema = rootRequire('Anguar/models/superhero');
module.exports = {
superhero_list: function(req, res) {
superheroSchema.find({}, function(err, superhero) {
if (err) {
return res.status(400).send({ "message": "Server error!", "err": err });
}
else {
return res.status(200).send({ "superheros": superhero });
}
}
};
superhero.html
<h1> Super heros</h1>
<table>
<thead>
<tr>
<th>S.no</th>
<th>Super hero</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
// to implement the table
</tr>
</table>
Problem I am facing is the response of the
return res.status(200).send({ "superheros": superhero });
is directly giving me response
{"Superheros":[{"_id":"582c5211c8a8e06c0849a238","name":"Superman"},{"_id":"583bf729a9de83840ca277dc","name":"Spiderman"},{"_id":"583bf78ca9de83840ca277de","name":"Batman"},{"_id":"583bf793a9de83840ca277df","name":"Shaktiman"},{"_id":"583bfc97a9de83840ca277e0","name":"Me"}]}
and not loading the superhero.html
how to get data into html?