-
Notifications
You must be signed in to change notification settings - Fork 85
Description
Currently:
The backend server calls app.listen(...) independently.
Database connection logic is handled separately in a controller/service.
This means the API starts even if the database is down, leading to runtime errors when endpoints are called.
Proposed Change:
Modify the startup flow so that the backend only starts (app.listen) after a successful database connection.
If the database fails to connect, the server should not run, and an error should be logged.
Advantages:
✅ Fail Fast Principle – prevents the server from running in a broken state.
✅ Better Reliability – avoids confusing runtime errors caused by missing DB connections.
✅ Cleaner Error Handling – startup logs clearly show database connection issues.
✅ Consistency – ensures that all APIs depending on the DB will work once the server is running.
Why This Should Be Added:
Right now, the app can misleadingly appear “healthy” (server listening), even if the database is unavailable. This could cause problems in production monitoring, CI/CD pipelines, or health checks. By enforcing database connectivity at startup, we guarantee the app only runs when fully functional.