Trying to return all the 'titles' of the news. It is not returning anything to frontend. What's the problem?
var table = [];
router.get('/api/v1/news', function (req, res) {
var title = req.params.title;
News.find({title: title}).toArray(function (err, news) {
if (err) {
res.send('error');
} else if (news.length > 0){
//table.push(news);
News.on('row', function (row) {
table.push(row);
});
// After all data is returned, close connection and return results
News.on('end', function () {
done();
return res.json(table);
});
}
});
});
via edu
No comments:
Post a Comment