I am a complete beginner in JavaScript / Node.js / Express, but have some experience with php.
I am trying to pass data from a SQLite database to the console. In my previous attempts, console.log() was executed before the database got queried. Now I got it to work in the correct order with what I think is a callback, and I'm getting the data in the console.
Questions:
-Is this an actual callback?
-Is there a better (shorter / easier) way to "do this after that"?
-If I want to execute multiple functions in a certain order, would I want to end up with something like doThis(doThat(thenDoThis(finallyDoThat)));?
-If there's anything else about the code, feel free to review and comment.
// Some test code to get data from database
function getAllChampions(callback){
db.all("SELECT * FROM champions", function(error, rows){
if (error) console.log(error);
return callback(error, rows);
});
};
function showAllChampions(error, champions){
if (error) console.log(error);
else console.log('Champions: ' + JSON.stringify(champions));
};
getAllChampions(showAllChampions);