Laura Beatris
Laura Beatris

Reputation: 1922

Postgres pool doesn't connect to the client

My postgres pool is not connecting to the client and i'm almost sure that i passed the right properties to it.

That's the pool instance:


const { Pool } = require('pg')

module.exports = new Pool({
    host: 'localhost',
    port: 5432,
    user: 'laura',
    password: 123,
    database: 'launchstore'
})

And i created the postgres service with docker-compose:

version: '3.3'

services:
  postgres:
    container_name: postgres
    image: postgres
    environment:
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_DB: ${POSTGRES_DATABASE}
    ports:
      - "5432:5432"
    restart: unless-stopped

My env file:

POSTGRES_DATABASE=launchstore
POSTGRES_PASSWORD=123
POSTGRES_USER=laura

When i enter the page, it keeps loading and that's the result why i try to log the pool instance:

Pool {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  options: {
    Client: [Function: Client] { Query: [Function: Query] },
    host: 'localhost',
    port: 5432,
    user: 'laura',
    password: 123,
    database: 'postgres',
    max: 10,
    idleTimeoutMillis: 10000
  },
  log: [Function (anonymous)],
  Client: [Function: Client] { Query: [Function: Query] },
  Promise: [Function: Promise],
  _clients: [],
  _idle: [],
  _pendingQueue: [],
  _endCallback: undefined,
  ending: false,
  ended: false,
  [Symbol(kCapture)]: false
}

If i'm passing the right properties and my container is running, why my client can't connect to the pool?

Upvotes: 1

Views: 653

Answers (1)

Laura Beatris
Laura Beatris

Reputation: 1922

The PG dependency wasn't installed correctly and that's why the pool wasn't working too. So it wasn't related to any configuration error.

Upvotes: 1

Related Questions