Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I struggled today to get my local node.js app to reach out to the db on Heroku instead of settling for a parallel db on my machine. Thanks to a post I tested and then stopped expecting

process.env.DATABASE_URL

to provide the URL and replaced it with the actual URL from

heroku config

along the lines of

var connectionString = "postgres://thinga:[email protected]:5432/thingc";.

But that didn't solve the problem completely. I found I also had to use

var pg = require('pg').native;

to force SSL. And in order to get that to work I had to rollback my pg module to

"pg": "2.x"

There must be a better way. Anyone?

P.S. I also set

NODE_ENV: development

but I don't know if that makes any difference.

share|improve this question

1 Answer 1

You helped me fix the same problem on my machine, but I didn't have to go as far as you did.

I had already changed process.env.DATABASE_URL to connectionString after declaring:

var connectionString = 'postgres://thinga:[email protected]:thingc';

Adding .native to var pg = require('pg'); seems to have made the difference for me.

  1. I did NOT need to change pg in the dependencies. I left it at "pg": "4.x".

  2. I did not use this: NODE_ENV: development.

But thank you so much for your help.

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.