W
W
Wayne12121212021-05-23 17:52:02
Web development
Wayne1212121, 2021-05-23 17:52:02

Docker postgres node error error: role "username" does not exist?

Hello!
I ran into a problem that when I run a node through docker (which I'm new to), I can't access the database.
I've searched everywhere and I don't understand what's going on...

//docker-compose.yml

version: "3"
services:
    db:
      image: postgres
      environment:
        POSTGRES_PASSWORD: password
        POSTGRES_USER: username
      volumes: 
        - './pgdata:/usr/src/data'
      ports: 
        - '5432:5432'

    server:
      image: node:alpine
      command: sh -c "npm install && npm run dev"
      volumes:
        - ./backend:/usr/src/client
      working_dir: /usr/src/client
      ports:
        - "8080:8080"
      environment:
        HOST: 127.0.0.1
      restart: always
      tty: true


//подключение к базе из ноды
const { Pool } = require('pg');

const pool = new Pool({
    max: 20,
    connectionString: 'postgres://username:[email protected]:5432/mydatabase',
    idleTimeoutMillis: 30000
});

module.exports = pool


60aa6be7d4f48703682161.png

As a result, I get such an error and I do not understand how to fix it.

What should I do and what am I doing wrong? I would be very grateful for any help!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dimonchik, 2018-12-22
@dimonchik2013

if presenting for a license is not scary - implement it on a stealth base, it’s business

K
ky0, 2021-05-23
@ky0

Well, what is not clear? The database does not contain the role with which you want to connect. Create it, issue the necessary rights.

D
Dmitry, 2021-05-24
@q2digger

Maybe some bits of old experiments remained? Let's try to forcibly recreate the database, shall we?
docker-compose up -d --force-recreate postgres

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question