I am new to NodeJS. I have the following snippet.
var connection = mysql.createConnection(dbConfig);
connection.connect(function(err) {
if (err)
console.log("MySQL Connection Error: ", err);
else
console.log("Connection successfully established");
});
connection.query("SELECT * FROM `members1617`;",function(err,rows) {
if (err)
console.log("err: ", err);
else
console.log("rows: ",rows);
connection.end();
});
Is this bad code? I think it is because there is no guarantee that connection.connect() is finished and the connection has been established before the query is activated. And id the query is esecuted before the connection is made then there will be all sorts of errors. How is the Async working here?