Sorry for this noob question, I'm beginner in Javascript. I am using the NodeJs MySQL package to connect my node application to my database. But after running the query successfully the program doesn't exit it stays there forever until I terminate it manually. I want the program to run the query and exit the program.
The code that I'm using:
var mysql = require("mysql");
var pool = mysql.createPool({
connectionLimit: 100,
host: "Hostname",
user: "User",
password: "Password",
database: "DB_name",
debug: false,
});
function sql_query() {
pool.getConnection(function (err, connection) {
if (err) {
console.log(err.code + ' : '+ err.sqlMessage);
return;
}
var query = "MY-QUERY_STRING";
connection.query(query, (error, results, fields) => {
connection.release();
if (error) {
console.log(error);
return;
}
console.log("Done");
return results;
});
});
}
var result = sql_query();
console.log(result);