Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js ECONNRESET error after a while idle

I'm using node.js and PostgreSQL as my database. I use the below code to connect my database.

 const pool = new pg.Pool(config);
pool.connect((err) => {
  if (err) {
    console.log(err);
    return;
  }
  console.log('connected to database', config.database);
});

and this is the config codes:

const crypto = require('crypto').randomBytes(256).toString('hex');
module.exports = {
    host:'192.168.87.8',
    user: 'fjavadpour',
    database: 'fj_correspondence',
    password: 'Fariba321',
    port: 5432,
    max: 200,
    secret:crypto,
    idleTimeoutMillis: 72000000
};

but my database connection will crash and stop after being idle about one hour. how can I fix it?

like image 323
fariba.j Avatar asked Mar 24 '26 06:03

fariba.j


1 Answers

Can you try adding keepAlive:true to your config and then check?

like image 142
Anshul Verma Avatar answered Mar 25 '26 19:03

Anshul Verma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!