【发布时间】:2022-04-21 01:25:12
【问题描述】:
这是我第一次使用 postgres,我正在尝试将它与 node.js 一起使用。我在 Ubuntu 中安装了 postgres 并创建了用户 admin
sudo -i -u postgres
createuser --interactive
在我的节点代码中,我尝试连接到 postgres:
let { Client } = require('pg');
conn = new Client({host:'localhost', port:5432, database:'web-viewer', user: 'admin'});
conn.connect();
但我收到此错误
UnhandledPromiseRejectionWarning:错误:用户“admin”的密码验证失败
我的 pg_hba.conf 是
local all postgres peer
然后我改成
local all postgres md5
尝试为我的管理员用户添加密码,但是当我再次“createuser --interactive”时,我收到此错误
createuser:错误:无法连接到数据库模板 1:致命:用户“postgres”的密码验证失败
如何准备 postgreSQL 以连接到节点?
【问题讨论】:
标签: javascript sql node.js postgresql