Kinnard Hockenhull
Kinnard Hockenhull

Reputation: 3010

Heroku-Postgres Connection String in Node app

Have a node app on heroku, trying to connect to postgres using node-postgres and 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 logs from $ heroku log show the heroku generated connection string is set:

2017-09-08T00:36:03.510529+00:00 app[web.1]: Starting DB with parameters: postgres://xxxxxx:[email protected]:5432/xxxxxxxx

But an actual query yields:

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)

Which implies that the connection string is not being set as it appears to be . . . Is this the case? If so why?

Upvotes: 1

Views: 502

Answers (1)

vitaly-t
vitaly-t

Reputation: 25840

Depends on the version of node-postgres, but since late v6.x it required that a connection string is passed into the constructor using new Pool({connectionString: 'postgres://...'}).

Upvotes: 1

Related Questions