I am using msnodesqlv8 to query my SQL database in Node.JS
I am calling this function, which returns undefined for the variable:
function check_db(){
const query = "my sql query";
sql.query(connectionString, query, (err, rows) => {
console.log(rows)
});
return rows //obviously this returns undefined when check_db() is called
}
I have also tried the following method, which hasn't worked
function check_db(){
var a;
const query = "my sql query";
sql.query(connectionString, query, (err, rows) => {
console.log(rows)
a = rows
});
return a //also returns undefined
}
Any help is massively appreciated