2 months ago
I’m trying to run a Node.js locally that connects to my Railway Postgres database. I’ve tested both the internal (postgres.railway.internal) and the public (gondola.proxy.rlwy.net) database URLs in my .env, but I keep encountering connection errors:
With the internal URL:
getaddrinfo ENOTFOUND postgres.railway.internalWith the public URL:
ECONNRESETor SSL errors such asThere was an error establishing an SSL connection
I’ve tried adding ?sslmode=require&sslnegotiation=direct to the public URL, and also removed redundant Postgres environment variables, but nothing works.
It seems that the database is only reachable from inside Railway containers, which prevents me from running locally.
Could you clarify if there’s any supported way to connect to a Railway Postgres database from a local Node.js application, or if I must run it inside Railway?
Thank you for your help!
2 Replies
2 months ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
2 months ago
hey so the internal url (postgres.railway.internal) will never work from your local machine , it's only accessible from services running inside railway itself. that's just how their private networking works
for local development you need to use the public url (gondola.proxy.rlwy.net). the ssl issue you're hitting is because railway uses self-signed certificates, so you need to configure your connection like this:
javascript
const { Pool } = require('pg');
const pool = new Pool({
connectionString: process.env.DATABASE_PUBLIC_URL,
ssl: {
rejectUnauthorized: false
}
});don't add the ssl params to the url string itself , do it in the config object instead. the rejectUnauthorized: false is necessary for railway's setup
when you deploy to railway later, then you switch to the internal url to avoid egress costs. but for local dev, public url with that ssl config is the way to go
hope this help you 