NodeJS mysql connection out of order

Viewed 30

I want to run a nodeJS server that accesses MySQL remotely. I have set up a connection, but then the query that I initiate does not finish (it runs async) before I attempt to display the data.

conpool.getConnection(function(err) {
  if (err) throw err;
  conpool.query("SELECT * FROM orders", function (err, result, fields) {
    if (err) throw err;
    console.log(result);
  });
});
console.log("Checkpoint")

Outputs Checkpoint and then []

I have read some questions on stack exchange and they seem to be using AJAX... They say some things about using callback functions, but it is all very confusing to me. Can someone please explain it relevant to my code, and in easy terms. I am coming from Python so I am not used to async problems at all.

I have also seen some things about async/await functions, and promisify stuff, but I can't find simple documentation online for those.

My server is set up for testing, so I can easily test out any suggestions.

0 Answers
Related