Cant connect to psql instance with node
buildingbuild
HOBBYOP

23 days ago

Code :

import pg from "pg"

export const client = new pg.Client({
connectionString: process.env.DATABASE_URL,
ssl: { rejectUnauthorized: false }
})

export async function dbSetup() {
try {
await client.connect()
console.log(process.env.DATABASE_URL)
}
catch (err) {
console.log(err)
}
}

AggregateError [ECONNREFUSED]:
at internalConnectMultiple (node:net:1134:18)
at afterConnectMultiple (node:net:1715:7) {
code: 'ECONNREFUSED',
[errors]: [
Error: connect ECONNREFUSED ::1:5432
at createConnectionError (node:net:1678:14)
at afterConnectMultiple (node:net:1708:16) {
errno: -61,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 5432
},
Error: connect ECONNREFUSED 127.0.0.1:5432
at createConnectionError (node:net:1678:14)
at afterConnectMultiple (node:net:1708:16) {
errno: -61,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 5432
}
]
}

Context
Im using the env databasepublicurl on railway to connect. Im I forgetting something

$10 Bounty

14 Replies

I would highly suggest using the private networking URL to connect your node application to the database.


buildingbuild
HOBBYOP

23 days ago

Which one is that

1464154505775022000


buildingbuild
HOBBYOP

23 days ago

I would be able to connect even if my application is not hosted on railway?


DATABASE_URL



I would suggest you host everything on Railway. Egress costs can get really expensive.


buildingbuild
HOBBYOP

23 days ago

Okay I see but while in development what can I use from my ide


You can start a postgres server locally. (I wouldn't suggest working on a prod database in a dev environment)


buildingbuild
HOBBYOP

23 days ago

Yh but that takes setup time. So is there not a way I can just use the url and definitely set up a local psql but I want to get something up and running


buildingbuild
HOBBYOP

23 days ago

Anyone?


You can definitely use the public URL to connect to the database. I just wouldn't recommend it:
1) Egress costs
2) One mistake in dev environment will completely destroy your prod database


buildingbuild
HOBBYOP

23 days ago

I understand that very well. Its just that when i use public url I get this


buildingbuild
HOBBYOP

23 days ago

^


I'd make sure you're able to access Railway domains (and the proxies).
One way to check this is to just ping the domain (without the port) and see if your machine is able to find where the URL is pointing to.


Loading...