Node.js express app fails to connect to PostgreSQL pool on startup [closed]

1 day ago 3
ARTICLE AD BOX

I am trying to connect my Express application to a local PostgreSQL database using the pg library, but the connection is failing on startup.

Here is my current server configuration and connection logic:

// 1. MIDDLEWARE app.use(morgan('dev')); app.use(express.json()); app.use(express.urlencoded({ extended: true })); app.use(express.static(__dirname)); // 2. DATABASE CONNECTION const pool = new Pool({ user: 'postgres', host: '127.0.0.1', database: 'Prince Farouk', password: 'your_password_here', port: 5432, }); // Test connection on startup pool.connect((err, client, release) => { if (err) { return console.error('Database connection failure:', err.stack); } console.log('Connected to PostgreSQL successfully!'); release(); });
Read Entire Article