N
Neon8mo ago
conscious-sapphire

Failing to connect to the DB.

I have a nodejs application and I have been trying to connect using the conncetion string but I have just been getting errors Here is the code const { Client } = require("pg"); require("dotenv").config(); const SQL = CREATE TABLE IF NOT EXISTS messages(id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY, username VARCHAR(255),message VARCHAR(255)); INSERT INTO messages (username,message) VALUES ('Yandhi','Hello') ; async function main() { console.log( "seeding", ); const client = new Client({ connectionString: process.env.DATABASE_URL, connectionTimeoutMillis: 10000, ssl: { rejectUnauthorized: false }, idle_in_transaction_session_timeout: 10000, }); await client.connect(); await client.query(SQL); await client.end(); } main();
No description
14 Replies
conscious-sapphire
conscious-sapphireOP8mo ago
@Conrad Ludgate
modern-teal
modern-teal8mo ago
Hmm. We've seen some bugs with nodejs before. I think your version is quite new though and should be fixed. A quick check, are you able to use psql to connect? Additionally, I see you're connecting to us-east-2. Can I just check your latency. Where are you connecting from?
conscious-sapphire
conscious-sapphireOP8mo ago
malawi like locally
modern-teal
modern-teal8mo ago
if you can, yes please run psql locally Yeah, I see. There might be a config flag to tell nodejs to increase the timeout. It's possible the TCP latency is too high for nodejs
conscious-sapphire
conscious-sapphireOP8mo ago
well previously when I didnt have the timeout I also got the errors
conscious-sapphire
conscious-sapphireOP8mo ago
when I run psql locally
No description
modern-teal
modern-teal8mo ago
Ah, I mean psql $DATABASE_URL to connect to neon. Sorry for the confusion
modern-teal
modern-teal8mo ago
https://r1ch.net/blog/node-v20-aggregateeerror-etimedout-happy-eyeballs
Start node with --network-family-autoselection-attempt-timeout 5000. This changes the 250ms timeout to 5000ms, giving the connection a much higher chance of succeeding before it's canceled.
This might be something you could also try when testing your nodejs app, if possible
Node v20, AggregateError ETIMEDOUT and Happy Eyeballs | r1ch.net
How a broken implementation will break your Node.js connections.
modern-teal
modern-teal8mo ago
The description seems to match what you're seeing
conscious-sapphire
conscious-sapphireOP8mo ago
like this
No description
modern-teal
modern-teal8mo ago
Does it work with quotes around the database URL? (also, best not to share passwords over public discord 😅 I'd recommend resetting your password in the neon console)
conscious-sapphire
conscious-sapphireOP8mo ago
lol realised that a bit late. connecting using url worked
modern-teal
modern-teal8mo ago
Yeah, then it's likely this issue with nodejs that becomes a bigger problem due to your distance from the US
conscious-sapphire
conscious-sapphireOP8mo ago
let me try that and I will get back to you

Did you find this page helpful?