繁体   English   中英

Node 应用程序中的 Heroku-Postgres 连接字符串

[英]Heroku-Postgres Connection String in Node app

在 heroku 上有一个节点应用程序,尝试使用 node-postgres 和 heroku-postgres 连接到 postgres。

const {Pool} = require('pg');
var connectionString = process.env.DATABASE_URL || {user:'bot',database:'myDB'};
const db = new Pool(connectionString);
console.log('Starting DB with parameters: '+connectionString);

来自$ heroku log Heroku 日志显示了 heroku 生成的连接字符串的设置:

2017-09-08T00:36:03.510529+00:00 app[web.1]: Starting DB with parameters: postgres://xxxxxx:xxxxxxxxx@ec2-184-xx-xx-xx.compute-1.amazonaws.com:5432/xxxxxxxx

但实际查询会产生:

2017-09-08T00:36:04.794422+00:00 app[web.1]: Error executing query Error: connect ECONNREFUSED 127.0.0.1:5432
2017-09-08T00:36:04.794425+00:00 app[web.1]:     at Object.exports._errnoException (util.js:1020:11)
2017-09-08T00:36:04.794426+00:00 app[web.1]:     at exports._exceptionWithHostPort (util.js:1043:20)
2017-09-08T00:36:04.794426+00:00 app[web.1]:     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)

这意味着连接字符串没有像看起来那样设置。 . . 是这种情况吗? 如果是为什么?

取决于node-postgres的版本,但自 v6.x 后期以来,它要求使用new Pool({connectionString: 'postgres://...'})将连接字符串传递到构造函数中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM