Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

427
Visualizações
how to create a user in postgres to connect to nodejs?

It is my first time using postgres and I am trying to use it with node. I installed postgres in Ubuntu and created the user admin

sudo -i -u postgres
createuser --interactive

in my node code I tried to connect to postgres:

let { Client } = require('pg');
conn = new Client({host:'localhost', port:5432, database:'web-viewer', user: 'admin'});
conn.connect();

but I get this error

UnhandledPromiseRejectionWarning: error: password authentication failed for user "admin"

my pg_hba.conf was

local   all             postgres                                peer

then I changed to

local   all             postgres                                md5

to try to add a password to my admin user, but when I "createuser --interactive" again, I get this error

createuser: error: could not connect to database template1: FATAL: password authentication failed for user "postgres"

how can I prepare the postgreSQL to connect to node?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You didn't parse the password in your new Client definition:

in my node code I tried to connect to postgres:

let { Client } = require('pg');
conn = new Client({host:'localhost', port:5432, database:'web-viewer', user: 'admin'});
conn.connect();

change it like the following, using the information you saved during the user creation:

let { Client } = require('pg');
conn = new Client({
    host:'localhost', 
    port:5432, 
    database:'web-viewer', 
    user: 'admin',
    password: 'yourpassword'  
});
conn.connect();

Follow the doc.

btw, to avoid using sensible information (your password), consider creating environment variables.


I know the post is 8 months old, but you never know.
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda