I'm Using NodeJs , why I'm not able to get the value of the data in collection variable here I'm using Nedb
router.get('/', (req, res) => {
var collection = [];
db.find({}, function (err, data) {
collection = data
});
res.render('../views/Client/index.ejs', { data: collection })
console.log(collection)
});
I also Try var collection =null and var collection; but still It not showing data. i have try all of these but these sill have issues. Get node.js neDB data into a variable
Because the callback is not being triggered before
res.render(...). It is like an asynchronous operation. Your callback function can work after your database finish to find data. You can try to useres.render(...)in your callback function