I have this express application with mongoDB as the database and handlebars as my server-side templating engine. I am not using AngularJS or Ajax in my application.
In one of the routes, I have to render the page as well as send over a json file from the database. However, I am not able to achieve this.
This is my code snippet from by route:
router.get('/disks', function(req, res, next) {
var risime;
places.find({"category": "disks"}, function(err, disk){
if(err){
throw err;
}
risime= disk;
console.log(risime); //PROPERLY LOGS THE OUTPUT
});
res.render('diskPage',
{
'disks': risime
});
});
In the hbs, I am trying to capture it, but I am not getting the json data:
var clrisime= "{{risime}}"
console.log(clrisime); // DOES NOT LOG ANYTHIN
How do I make it happen?