我正在尝试为我的React App配置与Postgresql的连接。
我花了几个小时解决这个问题,并阅读了大量关于此功能的博客和帖子。看来我对Postgresql的配置还可以,但是我无法通过Express登录。
这是我的server.js:
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const PORT = 4200;
const cors = require('cors');
const { Pool, Client } = require('pg')
const pool = new Pool({
user: 'postgres',
host: 'localhost',
database: 'postgres',
password: 'admin',
port: 5433,
})
app.use(cors());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.listen(PORT, function(){
console.log('Server is running on Port: ',PORT);
});
pool.query('SELECT NOW()', (err, res) => {
console.log(err, res)
pool.end()
})
我的pgpass.conf是:
localhost:5433:*:postgres:admin
127.0.0.1:5433:*:postgres:admin
最后,结果是:node src / server / server.js
Server is running on Port: 4200
{ error: authentification par mot de passe �chou�e pour l'utilisateur � postgres �
at Connection.parseE (D:\Projects\VSCode\liturgik-web\node_modules\pg\lib\connection.js:602:11)
at Connection.parseMessage (D:\Projects\VSCode\liturgik-web\node_modules\pg\lib\connection.js:399:19)
at Socket.<anonymous> (D:\Projects\VSCode\liturgik-web\node_modules\pg\lib\connection.js:121:22)
at Socket.emit (events.js:197:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:150:17)
name: 'error',
length: 187,
severity: 'FATAL',
code: '28P01',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file:
'd:\\pginstaller.auto\\postgres.windows-x64\\src\\backend\\libpq\\auth.c',
line: '336',
routine: 'auth_failed' } undefined
我是法语,这就是为什么错误消息使用我的语言。该消息表示:“ 用户postgres的密码验证失败”
结论
我很困惑。从早上开始,我就致力于Postgresql。我必须安装较新版本的PgAdmin,此时我更改了密码。感谢Valentin Garreau的帮助。我将密码更改为正确的密码,并且一切正常。祝你有美好的一天,对于这篇文章感到抱歉。
谢谢您的帮助。