确认PostgresDB容器已正确运行,并且端口号映射正确。
在NodeJS应用中使用正确的主机和端口号来连接PostgresDB容器。
示例代码:
const { Pool, Client } = require('pg'); const pool = new Pool({ user: 'postgres', host: 'localhost', // 改为正确的主机 database: 'mydb', password: 'mysecretpassword', port: 5432 // 改为正确的端口号 });
pool.query('SELECT NOW()', (err, res) => { console.log(err, res) pool.end() })