【发布时间】:2020-09-18 07:47:06
【问题描述】:
我正在尝试使用 Node 和 pg (https://node-postgres.com/) 库连接到远程 Postgresql 实例 (Aurora)。
我的代码如下所示:
const { Pool } = require('pg');
const pool = new Pool({
user: '-not-shown-',
host: '-not-shown-',
database: '-not-shown-',
password: '-not-shown-',
port: 5432,
});
console.log('Testing select now query...');
pool.query('SELECT NOW()', (err, res) => {
console.log(err, res);
pool.end();
if (!err) {
console.log(res);
} else {
console.log(err);
}
});
但是,我没有得到任何结果。查询结果或任何类型的错误都不是。 请注意,我能够在命令行中使用 psql 成功连接到数据库实例。 我正在使用 EC2 免费层级 Amazon Linux 2 AMI 实例。
注意,没有结果也没有错误。 我不知道发生了什么事。 我认为有问题,因为如果没问题,它会返回查询结果。 请帮忙。
【问题讨论】:
-
您是否在代码中硬编码了机器公共 IP(作为数据库 IP)?如果是,请尝试使用“localhost”。以及检查您的节点服务器日志。
标签: node.js postgresql amazon-ec2 node-postgres