The connect method that you have chained onto mysql.createConnection
does not return a connection. Instead you can do:
var mysqlConnection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '',
database : 'carousel',
debug : true,
});
mysqlConnection.connect(function(err) {
if ( !err ) {
console.log("Connected to MySQL");
} else if ( err ) {
console.log(err);
}
});
Or you can leave out the connect call altogether "a connection can also be implicitly established by invoking a query" - https://github.com/felixge/node-mysql#establishing-connections