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?