TuringsSolutions's picture
Update app.js
8a68fe7 verified
raw
history blame
677 Bytes
const express = require('express');
const { Client } = require('pg');
const app = express();
const port = 7860;
app.use(express.json());
const connectWithRetry = () => {
const client = new Client({
host: 'my_postgres_db',
user: 'user',
password: 'password',
database: 'mydatabase',
port: 5432,
});
client.connect(err => {
if (err) {
console.error('Failed to connect to database:', err);
setTimeout(connectWithRetry, 5000); // wait 5 seconds then retry connection
} else {
console.log('Connected to database');
}
});
};
connectWithRetry();
app.listen(port, () => {
console.log(`App running on port ${port}`);
});