【问题标题】:error in pg-pool module when using postgres module with nodejs and heroku将 postgres 模块与 nodejs 和 heroku 一起使用时 pg-pool 模块中的错误
【发布时间】:2016-06-29 03:06:43
【问题描述】:

我正在尝试在 Heroku 托管的 nodejs 服务器应用程序中使用 postgresql 数据库。

这是我在 app.js 中的 pg 代码:

var pg = require('pg');
pg.defaults.ssl = true;
pg.connect(process.env.DATABASE_URL, function(err, client) {
  if (err) throw err;
  console.log('Connected to postgres!');
});

和npm声明文件package.json:

{
  "name": "utility-app",
  "version": "0.0.1",
  "dependencies": 
  {
  "ejs": "*",
  "express": "3.3.x",
  "pg": "6.0.1",
  "simple-oauth2": "^0.7.0"
  },
  "engines": 
  {
  "node": "0.10.x",
  "npm": "1.2.x"
  }
}

这在我的本地环境中工作,但是当我将代码推送到 Heroku 时,服务器崩溃了:

Screenshot of console demonstrating the crash

感谢您的帮助,

日本

【问题讨论】:

    标签: node.js postgresql heroku


    【解决方案1】:

    pg-pool 使用的是 ES6 Promise,在您 Heroku 帐户上的 Node.js 版本(0.12 之前)中不支持该承诺。

    您需要使用更现代的 Node.js 版本,例如 4.x

    【讨论】:

      猜你喜欢
      • 2018-02-23
      • 2016-12-27
      • 1970-01-01
      • 2021-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多