Error: connect ECONNREFUSED 127.0.1.1:5432

Viewed 129

good day all, i am working with knex, postgresql and firebase and I created a postgres sever in pgadmin and I am try to connect to it, to run normal crud operations, but anytime I run the API in my postman, it shows this error:

>  {"verifications":{"app":"MISSING","auth":"MISSING"},"logging.googleapis.com/labels":{"firebase-log-type":"callable-request-verification"},"severity":"INFO","message":"Callable request verification passed"}
i  functions: Finished "bookDate" in ~1s
>  Error: connect ECONNREFUSED 127.0.1.1:5432
>      at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1247:16) {
>    errno: -111,
>    code: 'ECONNREFUSED',
>    syscall: 'connect',
>    address: '127.0.1.1',
>    port: 5432
>  }

this is my connection in my .env:

DB_URL=postgres://postgres:123@127.0.1.1/wheboo

the ipaddress, name and password is the same as the host in pgadmin: pgadmin

so I don't understand what the problem is. this is the code I'm trying to write:

const functions = require("firebase-functions");
require("dotenv").config({ path: '../.env' });
const db = require("./db.js");


exports.bookDate =
  functions
    .region('europe-west2')
    .https.onCall((data, context) => {
      db('users').select()
        .then(function (result) {
          console.log("result")
          return {
            status: 200,
            success: true,
            message: result
          };
        })
        .catch((e)=>{
          console.log(e)
        })

      


    }); 
1 Answers

Where does your pgadmin run? If it runs on the same host as the postgres database, then 127.0.0.1 is correct from its perspective. You should use the hostname of pgadmin in this case. And if that does not work look for the database hostname in the firebase settings.

If your pgadmin host is pgadmin-host.xyz then try this:

DB_URL=postgres://postgres:123@pgadmin-host.xyz/wheboo

Related