This is the first time I am using nodejs. I am trying to build a chatbot using dialogflow, and i am trying to access the database of my website hosted on a server. However, it is giving me an error of ETIMEDOUT, even though the port is open for user 'omkar'. I am able to access the database through my terminal on my device, by using the user 'omkar'. What could be the reason this error is encountered ? Here is my code :
function connectDataBase(){
const connection=mysql.createConnection({
host:'ip_of_my_database_server',
user:'omkar',
password:'my_password',
database:'database_name'
});
return new Promise((resolve,reject)=>{
connection.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
resolve(connection);
});}
function queryDataBase(connection){
return new Promise((resolve,reject)=>{
connection.query('SELECT * from auth_user',(error,results,fields)=>{
resolve(results);
});
});}
function handlerRank(agent){
return connectDataBase().then(connection=>{
return queryDataBase(connection).then(result=>{
console.log('Printing');
console.log(result);
agent.add(result[0].first_name);
connection.end();
});
});}
Edit 1:
I have checked whether my mysql database is accessible remotely or not. Port 3306 is accessible for an external client. Also, the user ‘omkar’ has appropriate permissions for viewing and updating the database.
I am using the dialogflow inline editor, in which the above code is written.