Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

428
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda