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
14 Replies
23 days ago
I would highly suggest using the private networking URL to connect your node application to the database.
I would be able to connect even if my application is not hosted on railway?
23 days ago
DATABASE_URL
23 days ago
No.
23 days ago
I would suggest you host everything on Railway. Egress costs can get really expensive.
23 days ago
You can start a postgres server locally. (I wouldn't suggest working on a prod database in a dev environment)
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
23 days ago
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
I understand that very well. Its just that when i use public url I get this
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.
