node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

node version 16 problem with pg connection

Open tinali233 opened this issue 2 years ago • 4 comments

Does anyone know how to solve the issue when the node version 16 is not working with pg connection? Tried to connect pg using pg version 8.7.3 and 7.4.3 with node 16, it gets 504 time out. switching with node version 12, it is working fine

tinali233 avatar May 24 '22 15:05 tinali233

+1, having a similar issue

jlbyrne avatar Jun 21 '22 21:06 jlbyrne

Same here. Can reproduce with node 17.0.1 on macos and with node 18.4.0 on Debian (node:18-bullseye-slim container from Docker hub).

const { Client } = require('pg');

const client = new Client({
  host: '....rds.amazonaws.com',
  user: 'postgres',
  password: '...',
  database: '...'
});

client.query('SELECT 1;').then(console.log).catch(console.error);

The query method returns a promise which is never resolved. Interestingly, using wrong credentials doesn't give any output either. Query runs fine using psql.

mauritsl avatar Jun 27 '22 15:06 mauritsl

@mauritsl You didn’t connect that client. await client.connect();

charmander avatar Jun 28 '22 01:06 charmander

Thanks, makes sense.

I wrapped the last line in a connect like this:

client.connect().then(() => {
  client.query('SELECT 1;').then(console.log).catch(console.error);
}).catch(console.error);

This works on node 12, 16, and 18 on Debian and node 17 on macos (using pg 8.7.3).

Maybe the TS can provide their code as well, since I cannot reproduce the issue anymore?

mauritsl avatar Jun 28 '22 05:06 mauritsl