I am trying to write a function to get data from a database, but the code in the function doesn't seem to be getting run from top to bottom. This is my code:
function getTextDb(id){
db.get(id).then(function(doc){
console.log("This is what should show: " + doc.text); //Just to show what should be returned
return "This is what the return should show: " + doc.text;
});
}
but then when I run console.log(getTextDb('randomText')) (This is a piece of data in the database) it shows this in the console (ignore the color, it's just stack overflow adding it):
undefined
This is what should show: Just some random text
Which means it's returning before getting to the actual return statement. What is going on?