最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

Postgres服务器未响应nodejs请求

IT培训 admin 11浏览 0评论

Postgres服务器未响应nodejs请求

我可以从pgAdmin4访问远程postgres数据库,也可以使用Mac从nodejs访问。现在,我正在使用相同的代码来访问Windows中的数据库。我的连接代码如下:

const { Client } = require('pg'); //Importing the Postgres package
const hosts= require('../hosts'); //Using the file containig all hosts 
const connectionData = { //Begin creating the connection settings object
   host: hosts.DBHost, //DB host   
   port: hosts.DBPort, //DB hosts port
   database: hosts.DB, //DB
   user: hosts.DBUser, //DB user
   password: hosts.DBPassword, //DB user password
 } 

我的测试如下:

var client = new Client(connectionData); //New client instance using the above connection settings
client.connect(); //Open the connection to the database()  
sql = "select * from myTable";
client.query(sql) 
  .then(response => {
    console.log ({"data": response}); //This isn't shown 
  })
  .catch(err => { 
    console.log({"error": err}); //This isn't shown neither 
  })

没有错误,没有异常,数据库服务器没有响应!

为什么服务器没有响应?

回答如下:

我怀疑您有与此other post中相同的问题。由于不是100%重复,因此我将再次发布:

[pg模块和NodeJS 14中有一个known issue。

建议的解决方案是确保已安装pg>=8.0.3

这可以通过更新依赖项中的pg来完成。

还请确保任何其他依赖于pg模块的库也都是最新的,并且具有最新的pg版本。

如果由于某种原因无法实现-使用节点12也可以。

Postgres服务器未响应nodejs请求

我可以从pgAdmin4访问远程postgres数据库,也可以使用Mac从nodejs访问。现在,我正在使用相同的代码来访问Windows中的数据库。我的连接代码如下:

const { Client } = require('pg'); //Importing the Postgres package
const hosts= require('../hosts'); //Using the file containig all hosts 
const connectionData = { //Begin creating the connection settings object
   host: hosts.DBHost, //DB host   
   port: hosts.DBPort, //DB hosts port
   database: hosts.DB, //DB
   user: hosts.DBUser, //DB user
   password: hosts.DBPassword, //DB user password
 } 

我的测试如下:

var client = new Client(connectionData); //New client instance using the above connection settings
client.connect(); //Open the connection to the database()  
sql = "select * from myTable";
client.query(sql) 
  .then(response => {
    console.log ({"data": response}); //This isn't shown 
  })
  .catch(err => { 
    console.log({"error": err}); //This isn't shown neither 
  })

没有错误,没有异常,数据库服务器没有响应!

为什么服务器没有响应?

回答如下:

我怀疑您有与此other post中相同的问题。由于不是100%重复,因此我将再次发布:

[pg模块和NodeJS 14中有一个known issue。

建议的解决方案是确保已安装pg>=8.0.3

这可以通过更新依赖项中的pg来完成。

还请确保任何其他依赖于pg模块的库也都是最新的,并且具有最新的pg版本。

如果由于某种原因无法实现-使用节点12也可以。

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论