Spaces:
Sleeping
Sleeping
File size: 677 Bytes
d922d99 4f5e139 d922d99 4f5e139 df83b24 58903fd 8a68fe7 58903fd df83b24 58903fd d922d99 7ad5f6c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
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}`);
});
|