NodeJ和node-postgres代码在EC2中未返回任何响应

问题描述

我正在尝试使用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实例。

代码在我的本地计算机上工作,并且得到如下结果:

enter image description here

但是当我使用Ec2机器时,我得到的只是:

enter image description here

注意,没有结果,也没有错误。 我不知道发生了什么。 我认为有问题,因为如果可以的话,它会返回查询结果。 请帮忙。

解决方法

更新:

我找到了答案: https://github.com/brianc/node-postgres/issues/2069

当前版本的node-postgres和pg-promise与最新版本的node不兼容。我当时使用的是Node14。我将其降级为12,现在可以正常工作了。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...