Trying to connect to a SQL database using javascript but I keep getting this error:
Database connection failed: Error: connect ETIMEDOUT
at Connection._handleConnectTimeout (/Users/------/PhpstormProjects/------/node_modules/mysql/lib/Connection.js:409:13)
at Object.onceWrapper (events.js:421:28)
at Socket.emit (events.js:315:20)
at Socket._onTimeout (net.js:480:8)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7)
Have scoured the web but cannot find any solution. What am I doing wrong? Here is my code:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : "----.---------.-------.amazonaws.com",
user : "--------",
password : "--------"
});
connection.connect(function(err) {
connection.end();
if (err) {
console.error('Database connection failed: ' + err.stack);
return;
}
console.log('Connected to database.');
});