I am trying to end my mysql connection in my node program. I can successfully do that using something like connection.end(). However, when I do that it doesn't seem to run the queries before that. If I leave the end statement out my insert queries before this seem to run, however the program then hangs and it just never ends.
Here is my code
var mysql = require('mysql');
var connection = mysql.createConnection({'...'});
connection.connect(function(err){
});
for(var a=0; a<ticker.length;a++){
if(result[i].tweetText.indexOf(ticker[a]) > -1){
for(var j=0; j<positive.length;j++){
if((result[i].tweetText.indexOf(positive[j]) > -1) && check > -1){
console.log(result[i].tweetText + "\n")
plus++;
console.log(ticker[a] + "plus"+plus +"\n")
check = -1;
connection.query("insert into....", function(err, result) {
});
}
}
}
}
connection.end();
Having the end successfully terminates connection, but then all my insert statements do not run; when I remove the end connection statement, my insert statement runs but the program hangs.