节点应用程序中的Heroku-Postgres连接字符串
问题描述:
在heroku上有一个节点应用程序,尝试使用node-postgres和heroku-postgres连接到postgres。节点应用程序中的Heroku-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:[email protected]: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://...'})
将连接字符串传递给构造函数。