-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (35 loc) · 1.29 KB
/
server.js
File metadata and controls
41 lines (35 loc) · 1.29 KB
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
33
34
35
36
37
38
39
40
41
import dotenv from 'dotenv';
import app from './src/app.js';
import connectDB from './src/config/db.js';
// Load environment variables
dotenv.config();
// Constants
const PORT = process.env.PORT || 8000;
/**
* Start Server
*/
const startServer = async () => {
try {
// Connect to MongoDB
await connectDB();
// Start Express server
app.listen(PORT, () => {
console.log('═══════════════════════════════════════════');
console.log(`🚀 ILMS Backend Server`);
console.log(`📍 Environment: ${process.env.NODE_ENV || 'development'}`);
console.log(`🌐 Server running on port ${PORT}`);
console.log(`🔗 API URL: http://localhost:${PORT}/api`);
console.log('═══════════════════════════════════════════');
});
} catch (error) {
console.error('❌ Failed to start server:', error);
process.exit(1);
}
};
// Handle unhandled promise rejections
process.on('unhandledRejection', (err) => {
console.error('❌ Unhandled Promise Rejection:', err);
process.exit(1);
});
// Start the server
startServer();