import express from 'express'; import cors from 'cors'; import { initDB } from './db.js'; import authRoutes from './routes/auth.js'; import taskRoutes from './routes/tasks.js'; const app = express(); const PORT = process.env.PORT || 3001; app.use(cors()); app.use(express.json()); // Routes app.use('/api/auth', authRoutes); app.use('/api/tasks', taskRoutes); // Health check app.get('/api/health', (_req, res) => { res.json({ status: 'ok', timestamp: new Date().toISOString() }); }); // Initialize DB and start server async function start() { try { await initDB(); app.listen(PORT, () => { console.log(`🚀 Backend server running on port ${PORT}`); }); } catch (err) { console.error('❌ Failed to start server:', err); process.exit(1); } } start();