Can't connect to Postgres database
mike-benn
HOBBYOP

2 years ago

Admittedly I'm very new to back-end stuff and am learning so apologize if this is stupid.

I've got a small form I've created in React to just get experience with making requests to a database hosted on here. It's being hosted on Vercel and my backend and database are being hosted here in a project together. When I make a post request to the database I keep getting an error and I've tried to google and other things to figure out what's going on but nothing is working for me.

This is the error I'm getting:

Error: connect ECONNREFUSED ::1:5432

Sep 02 05:09:02

cridr-app-backend

at /app/node_modules/pg-pool/index.js:45:11

Sep 02 05:09:02

cridr-app-backend

at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Sep 02 05:09:02

cridr-app-backend

at async /app/controllers/couponController.js:8:5

My db.js file is pretty small, not sure if I'm screwing up the connection string or something but I'm just using the default connection variable provided by Railway. Appreciate any help.

require('dotenv').config();
const { Pool } = require('pg');

const pool = new Pool({
    connectionString: process.env.DATABASE_URL,
});

module.exports = pool;

0 Replies

Loading...