Facing the following problem: there is a simple web application (node.js/express/mongodb). user enters product id and the application shows price.
function queryDb(var id) {
// connect mongodb
// find product price for id
return price
}
app.post("/", function(req,res) {
var id = req.body.id;
var price = queryDb(id);
// ---> wait here for the query to finish
res.render('index', {price: price})
})
the app runs faster then the db query. how can I force the code to wait for queryDb() function to finish and return the price? I have tried callbacks, promises, async/await - always the same.