从本地Node.js Web应用程序访问Heroku上的远程Postgres DB时遇到问题 [英] Trouble Accessing Remote Postgres DB on Heroku from Local Node.js Webapp

查看:73
本文介绍了从本地Node.js Web应用程序访问Heroku上的远程Postgres DB时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天在努力让本地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'); 似乎对我有所帮助。


  1. 我不需要更改依赖项中的 pg 。我将其保留在 pg: 4.x


  2. 我没有使用它: 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.

  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.

这篇关于从本地Node.js Web应用程序访问Heroku上的远程Postgres DB时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆