Pg Promise timeout while using express generator format, but works fine with basic express sever
Asked Answered
N

0

0

Pg-promise is Not returning anything for 60s and gets timed out while running server setup with express-generator. There are no error messages.

All the routes without db.any or similar query, works fine. The routes with db.* times out.

But, the same connection/route/query works perfectly with a simple express app.

I am running this from AWS EC2.

Here is the test sample express that worked fine. Same route in routes/index.js does not work - gets timed out.

const express = require('express');
const app = express();

const options = {
  query: function (e) {
    console.log(e.query);
  },
};

const pgp = require('pg-promise')(options);
const connection = 'postgres://user:pwd@endpoint:5432/db';
const db = pgp(connection);

app.get('/test', (req, res) => {
  db.any('select id from users')
    .then(data => {
      res.json({
        data,
      });
    }).catch(err => {
      res.json({
        err,
      });
    });
});

app.listen(4000, () => {
  console.log('db app listening on port 4000!');
});

module.exports = app;

Not sure what I am missing? What could be the issue!

Nevis answered 4/12, 2020 at 23:10 Comment(3)
More info: The problem seems to occur when pg connection is created in another file and being imported to routes!! Not exactly an express-generator issue. But still unresolved.Nevis
It's all AWS-related issues, of which there have been numerous discussions against the underlying driver.Yeung
I see. Thanks for replying. The same setup is working fine on local as well as other AWS instances is what I observed too.Nevis

© 2022 - 2024 — McMap. All rights reserved.