require('dotenv').config(); const app = require('./app'); const { testConnection, disconnect } = require('./utils/db'); const PORT = process.env.PORT || 3000; async function startServer() { // Test database connection await testConnection(); const server = app.listen(PORT, '0.0.0.0', () => { console.log('================================='); console.log('🚀 spotlight.cam Backend Started'); console.log('================================='); console.log(`Environment: ${process.env.NODE_ENV || 'development'}`); console.log(`Server running on port: ${PORT}`); console.log(`Health check: http://localhost:${PORT}/api/health`); console.log('================================='); }); return server; } startServer().catch((err) => { console.error('Failed to start server:', err); process.exit(1); }); // Graceful shutdown process.on('SIGTERM', async () => { console.log('SIGTERM received, shutting down gracefully...'); await disconnect(); process.exit(0); }); process.on('SIGINT', async () => { console.log('SIGINT received, shutting down gracefully...'); await disconnect(); process.exit(0); });