【问题标题】:Heroku H12 “Request Timeout” error on using db.query method node.js使用 db.query 方法 node.js 时出现 Heroku H12“请求超时”错误
【发布时间】:2021-05-10 10:16:02
【问题描述】:

每当我尝试从 Heroku 应用 Node.js 连接 Postgres 数据库时,我都会收到 H12“请求超时”错误。我以为是因为没有将响应发送到前端,在用没有 db.query 方法的函数确认后。它工作正常。现在,每当我们尝试使用 db.query 时,流程都会终止。我是 Heroku 和 Postgres 数据库的新手。帮我解决这个问题

    var pgp = require("./pgpromise.js");
var cn = {
  host: "xxxx", // 'localhost' is the default;
  port: 5432, // 5432 is the default;
  database: "xxx",
  user: "xxx",
  password: "xxx",
};
var db = pgp(cn); // database instance;
module.exports = db;



app.post("/getaccount", async (req,res) =>{
  var query = "select * from table_name";
  await db.query(query, true)
      .then(function (data) {
        return res.json(data);
      })
      .catch(function (err) {
        console.log("ERROR:", err); // print the error;
        return res.status(400).json({ success: false, error: err });
      })
  });

【问题讨论】:

    标签: node.js heroku heroku-postgres heroku-api


    【解决方案1】:

    我遇到了同样的问题,在部署到 heroku 之前,我在 package.json 中指定了引擎版本解决了这个问题。类似的东西:

    ...
        "engines": {
            "node": "12.18.3"
          }
    ....
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-14
      • 2017-06-10
      • 1970-01-01
      • 2020-07-09
      • 2019-09-13
      • 1970-01-01
      • 1970-01-01
      • 2019-12-15
      相关资源
      最近更新 更多