3

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?

3
  • Where is your host? Is it within the same network? Commented Mar 28, 2018 at 7:51
  • github.com/brianc/node-postgres/issues/… ?.. Commented Mar 28, 2018 at 7:51
  • @AnshulVerma yes! I can connect to the host at first but it crashes and get ECONNRESET error when I don't contact to the database after about an hour Commented Mar 28, 2018 at 8:14

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.