node-postgres
node-postgres copied to clipboard
node version 16 problem with pg connection
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
+1, having a similar issue
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 You didn’t connect that client. await client.connect();
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?