Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres server is not responding to a nodejs request

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?

like image 928
Maf Avatar asked Mar 03 '23 11:03

Maf


1 Answers

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.

like image 97
madflow Avatar answered Mar 05 '23 16:03

madflow