Postgres server is not responding to a nodejs request

隐身守侯 提交于 2021-02-04 08:14:25

问题


I have access to a remote postgres DB from pgAdmin4 and I also could access from nodejs using a Mac. Right now I'm using the same code to access the DB in Windows. The code for my connection is the following:

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
 } 

My test is the following:

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

No error, no exception, the DB server doesn't respond!

Why isn't the server responding?


回答1:


I suspect that you have the same problem like in this other post. Since it is not a 100% duplicate I will post this again:

There is a known issue in the pg module and NodeJS 14.

The proposed solution is to make sure you have pg>=8.0.3 installed.

This can be done by updating pg in the dependencies.

Also make sure, that any other library depending on the pg module, is also up to date and has the latest pg version.

If this is not possible for any reason - using Node 12 should also work.



来源:https://stackoverflow.com/questions/61611039/postgres-server-is-not-responding-to-a-nodejs-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!