Home > Net >  ETIMEDOUT while connecting remote mysql database from node.js app on heroku server
ETIMEDOUT while connecting remote mysql database from node.js app on heroku server

Time:03-24

Example of the code I use:

const connection = mysql.createPool({
    host: process.env.NEXT_DB_HOST, //*******.timeweb.ru
    database: process.env.NEXT_DB_DATABASE, //c*****_tech
    user: process.env.NEXT_DB_USER, //c*****_tech
    password: process.env.NEXT_DB_PASSWORD, //******
    waitForConnections: true,
    connectTimeout: 100000,
    connectionLimit: 10,
    queueLimit: 0
});

connection.query(
    "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'",
    (err, results, fields) => {
         if(err) console.log(err);
         console.log(results);
         console.log(fields);
    }
);

All vars are added in heroku. Also the domain is added to timeweb panel as "Access db point". I know that heroku has dinamic IP, so how can I connect remote db?

CodePudding user response:

Timeweb use only static IP-address for connecting, but heroku has dinamic. It's better to change hosting, for node.js apps it could be any VPS such as Timeweb.

  • Related