我按照以下步骤操作: https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction
当我运行 heroku local 时,它无法连接 - 我看到它正在使用 process.env.DATABASE_URL 并使用以下方法将其获取到我的本地 .env 文件: https://devcenter.heroku.com/articles/heroku-local
但仍然无法连接,我添加了一个console.log来查看错误:
“错误:主机“62.90.xxx.yyy”、用户“用户名”、数据库“密码”、SSL 关闭没有 pg_hba.conf 条目
现在怎么办?
最佳答案
经过大量搜索后发现,添加“pg.defaults.ssl = true”为我解决了问题,同时让我尽可能接近 Heroku 提供的示例。
这是我的代码
const cool = require('cool-ascii-faces');
const express = require('express')
const path = require('path')
const PORT = process.env.PORT || 5000
const pg = require('pg');
pg.defaults.ssl = true; //this is it!!!
express()
.use(express.static(path.join(__dirname, 'public')))
.set('views', path.join(__dirname, 'views'))
....
关于node.js - 无法使用 Node 示例从heroku local连接到heroku postgres,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49606515/