I have a problem getting the restaurantname from the db with node.js, it seems it has to do something with callback parameters but I can’t find the solution for my case, hopefully one of you can help me .
I have made function who gets the name of the restaurant from a database. The first console log line gives the right retvalue and the second one gives undefined, how can I write the code so that the return value is the name of the restaurant?
Kind regards, Robert
function restaurantName(id) {
var retvalue;
try {
F.model('restaurant').load(id).then(function (restaurant) {
retvalue = restaurant.Name;
console.log('restaurantName 1(' + id + ')' + retvalue);
})
} catch (err) {
retvalue = 'Error';
}
console.log('restaurantName 2(' + id + ')' + retvalue);
return retvalue;
};