1

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?

1 Answer 1

1

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://...'}).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.