Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I try to connect to my postgres database on Heroku by:

var pg = require('pg');
pg.defaults.ssl = true;
var pool = new pg.Pool(process.env.DATABASE_URL);

pool.connect(function(err, client, done) {
if(err) {
  return console.error('error fetching client from pool', err);
}

I have confirmed the value of proccess.env.DATABASE_URL it has the right format, and I can successfully connect to it via psql postgres://XXXXXXXX:[email protected]:5432/XXXXXXXX

This is the output, and what confuses me is the 127.0.0.1 reference if this output.

2016-06-27T14:58:52.714154+00:00 app[web.1]: Express server listening on port 18119
2016-06-27T14:59:29.175122+00:00 app[web.1]: error fetching client from pool { Error: connect ECONNREFUSED 127.0.0.1:5432
2016-06-27T14:59:29.175133+00:00 app[web.1]:     at Object.exports._errnoException (util.js:949:11)
2016-06-27T14:59:29.175134+00:00 app[web.1]:     at exports._exceptionWithHostPort (util.js:972:20)
2016-06-27T14:59:29.175135+00:00 app[web.1]:     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1080:14)
2016-06-27T14:59:29.175136+00:00 app[web.1]:   code: 'ECONNREFUSED',
2016-06-27T14:59:29.175137+00:00 app[web.1]:   errno: 'ECONNREFUSED',
2016-06-27T14:59:29.175137+00:00 app[web.1]:   syscall: 'connect',
2016-06-27T14:59:29.175138+00:00 app[web.1]:   address: '127.0.0.1',
2016-06-27T14:59:29.175139+00:00 app[web.1]:   port: 5432 }
share|improve this question

Try this:

var pg = require('pg').native
pg.connect(process.env.databaseURL, function (err, conn, done) {
    ...
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.