简体   繁体   English

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

[英]NodeJs and node-postgres code is not returning any response in EC2

I am trying to connect to a remote Postgresql instance (Aurora) using Node and the pg ( https://node-postgres.com/ ) library.我正在尝试使用 Node 和 pg ( https://node-postgres.com/ ) 库连接到远程 Postgresql 实例 (Aurora)。

My code looks like this:我的代码如下所示:

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);
  }
});

However, I get no result whatsoever.但是,我没有得到任何结果。 Neither the query result or any sort of error.无论是查询结果还是任何类型的错误。 Note that I am able to successfully connect to the database instance using psql in the commandline.请注意,我能够在命令行中使用 psql 成功连接到数据库实例。 I am using an EC2 Free tier Amazon Linux 2 AMI instance.我正在使用 EC2 免费层 Amazon Linux 2 AMI 实例。

The code works on my local machine and I get a result that looks like this:该代码在我的本地机器上运行,我得到如下所示的结果: 在此处输入图片说明

But when I ssh into the Ec2 machine, all I get is this:但是当我通过 ssh 进入 Ec2 机器时,我得到的只是: 在此处输入图片说明

Notice, no result and no error either.注意,没有结果也没有错误。 I do not know what is going on.我不知道这是怎么回事。 I assume there is a problem, since it would have returned the query result if it was ok.我认为有问题,因为如果没问题,它会返回查询结果。 Please help.请帮忙。

Update:更新:

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

The current versions of node-postgres and pg-promise are not compatible with the latest version of node.当前版本的 node-postgres 和 pg-promise 与最新版本的 node 不兼容。 I was using Node 14. I downgraded to 12 and it is now working perfectly.我使用的是 Node 14。我降级到 12,现在它运行良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM