Can't connect to Postgres database Error: connect ECONNREFUSED ::1:5432

mike-bennTRIAL

8 months 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. My frontend is 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. I also have the railway things pointing to a subdomain I have set up on Cloudflare and my Vercel frontend is pointing to the main domain, I'm not sure if there's issues coming from this. Both domains load if I visit them without any console errors so I'm assuming I got them set up correctly on Cloudflare. I've seen things about turning off proxying for your api on Cloudflare and did that with the subdomain my railway deployment is using.

These are the logs I get when project is deployed and shortly after I make a post request I get an ECONNREFUSED error.

https://pastebin.com/8cAbsuf2

My db.js file and app.js file are 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.

const express = require("express");
const app = express();
const cors = require('cors');
const couponRouter = require("./routes/couponRouter");
require('dotenv').config();

const corsOptions = {
    origin: 'https://cridr-app.vercel.app/', 
    methods: ['GET', 'POST', 'PUT', 'DELETE'],
    allowedHeaders: ['Content-Type'],
};
app.use(cors(corsOptions));

app.use(express.urlencoded({ extended: false }));

app.get("/", (req, res) => res.send("Hello World!"));
app.use("/coupon", couponRouter);
const port = process.env.PORT || 3000;


app.listen(port, "0.0.0.0", () => console.log(`My first Express app - listening on port ${port}`))
require('dotenv').config();
const { Pool } = require('pg');

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

module.exports = pool;

0 Replies

Can't connect to Postgres database Error: connect ECONNREFUSED ::1:5432 - Railway Help Station