I'm new in node.js and express framework. I tried to figure out connection with external database, using this code:
var mysql = require('mysql');
var client = mysql.createConnection({
user: 'user',
password: 'pass',
host: 'db.myprovider.com',
database: 'test_database'
});
module.exports = {
getDataFromUserGps: function(callback){
client.query("SELECT * FROM userGps",
function(err, results, fields) {
if (err) return callback(err, null);
console.log('results: ', results);
return callback(null, results);
}
);
}
}
And I'm calling it here:
mysql.getDataFromUserGps(function(err, mysqlResult){
if(err) {
console.log('mysql error', err);
} else {
console.log('mysqlResult', mysqlResult);
}
});
Here's what I get:
mysql error { [Error: getaddrinfo ENOENT]
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
fatal: true }
And here' my question. I've read about common solution to this issue like 'not using "http" at the beginning' or possible issue with unix socet. But, with the very same config, i can easly connect using php, so I'm wondering if it can be somehow resolved by changing socet in my node.js application?
Thanks in advance!