node-postgres,连接意外终止

新手上路,请多包涵

我正在尝试使用 node-postgres 连接到远程数据库。

我可以使用 psql 客户端连接,但在尝试运行它时出现错误 Connection terminated unexpectedly (使用与 psql 客户端相同的连接字符串):

 const { Pool, Client } = require('pg')
const connectionString = '...'

const pool = new Pool({
  connectionString: connectionString,
})

pool.query('SELECT NOW()', (err, res) => {
  console.log(err, res)
  pool.end()
})

const client = new Client({
  connectionString: connectionString,
})
client.connect()

client.query('SELECT NOW()', (err, res) => {
  console.log(err, res)
  client.end()
})

我也一直在尝试连接 Sequelize ORM,但遇到了同样的错误。

@编辑

使用本机模式修复了使用 pg 和 sequelize 进行客户端查询的问题

const { Pool, Client } = require('pg').native

原文由 John Jeromin 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 726
1 个回答
推荐问题