从本地Node.js Web应用程序访问Heroku上的远程Postgres DB时遇到问题 [英] Trouble Accessing Remote Postgres DB on Heroku from Local Node.js Webapp
问题描述
我今天在努力让本地node.js应用程序接触Heroku上的数据库,而不是在我的机器上解决并行数据库的问题。感谢我测试过的帖子,然后不再期望
process.env.DATABASE_URL
提供URL并将其替换为
heroku配置
var connectionString = postgres:// thinga:thingb@ec2-23-21-119-36.compute-1.amazonaws.com:5432 / thingc;
。
但这并不能完全解决问题。我发现我还不得不使用
var pg = require(’pg’)。native;
强制使用SSL。为了使它正常工作,我必须将pg模块回滚到
pg: 2.x
必须有更好的方法。有人吗?
P.S。我还设置了
NODE_ENV:开发
但我不知道这有什么区别。
您帮助我解决了在我的计算机上出现了同样的问题,但是我不必走得太远。
我已经更改了 process.env.DATABASE_URL 声明后,将更改为 connectionString :
var connectionString ='postgres:// thinga:thingb @ ec2-54-204- 42-119.compute-1.amazonaws.com:thingc';
在 var pg中添加 .native = require('pg'); 似乎对我有所帮助。
-
我不需要更改依赖项中的 pg 。我将其保留在 pg: 4.x 。
-
我没有使用它: NODE_ENV:开发。
但是非常感谢您的帮助。
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:thingb@ec2-23-21-119-36.compute-1.amazonaws.com: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.
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:thingb@ec2-54-204-42-119.compute-1.amazonaws.com:thingc';
Adding .native to var pg = require('pg'); seems to have made the difference for me.
I did NOT need to change pg in the dependencies. I left it at "pg": "4.x".
I did not use this: NODE_ENV: development.
But thank you so much for your help.
这篇关于从本地Node.js Web应用程序访问Heroku上的远程Postgres DB时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!