Access Refused while using PG


I am trying to use PostgreSQL with the module pg in my glitch project, but while trying to connect I get an error:

11:18 AM
    at Object._errnoException (util.js:1019:11)
11:18 AM
    at _exceptionWithHostPort (util.js:1041:20)
11:18 AM
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1175:14```

Is there a workaround around this?


Hi @Soumil07. Can you let us know what you’re using when passing the pg package your Pg connection string? I’m asking since I’ve never seen that error before from pg so I just want to make sure you’ve got the right format for it. Note: I don’t need your actual connection string (please don’t give it to me) but what it looks like.

For example, when I connect to my Compose Postgres database, my format string looks like this. I’m posting it here so you can see if you have something resembling it.


Yours might look similar but obviously with different username, password, database name, host and perhaps port too.

And here is how I get a pg.pool using the connection string:

const pool = new pg.Pool({
  connectionString : process.env.DATABASE_URL

Other than that I’ve got no other suggestions unless you could perhaps paste us more code or link to your project so we can take a look. Thanks. :smile:


I am also having a similar issue.
SequelizeConnectionRefusedError: connect ECONNREFUSED
^ is the error I am getting.

while te one below is my code:

const Sequelize = require('sequelize');

const db = new Sequelize('database', process.env.DB_USER, process.env.DB_PASS, {
  host: 'localhost',
  dialect: 'postgres',
  logging: false,
  operatorsAliases: Sequelize.Op

// and I have written the below codes inside a async functon
await db.authenticate();

But I am happening to get that error I posted at the top.
Any help regarding the fix is highly appreciated. :smiley:


Hi @Froosty,

You can’t connect to localhost:5432 as there is no postgresql server running inside your project. You’ve to use a third party service for postgresql databases.