I'm trying to connect to MySQL with NodeJS. This is the code I have for connecting:
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "user",
password: "pass"
});
con.connect(function(err) {
if (err){
console.error('error connectiong'+ err.stack);
return;
}
console.log('Connected as Id' + connection.threadId);
});
Pretty straightforward and it should work but it doesn't. I've tried the following to resolve this with no luck:
- I've entered the port:3306 with no help;
- removed the password and left password:'' empty, but with no results
- added GRANT privileges to the user atop off all other privileges
- reset XAMPP after the changes
But I still get the same message:
I can't understand why I can't connect. I've checked other questions like this, tried some of the solutions and they didn't work. Any ideas? Thx.
