-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (36 loc) · 1.07 KB
/
Copy pathserver.js
File metadata and controls
43 lines (36 loc) · 1.07 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
42
43
require('dotenv').config()
const app = require('./app')
const connectDB = require('./config/db')
const winston = require('winston')
// Handle uncaught exceptions
process.on('uncaughtException', (err) => {
winston.error('Uncaught Exception:', err)
process.exit(1)
})
// Connect to MongoDB
connectDB()
const PORT = process.env.PORT || 3000
const server = app.listen(PORT, () => {
winston.info(`Jerota Backend Server running on port ${PORT}`)
winston.info(`Environment: ${process.env.NODE_ENV || 'development'}`)
})
// Handle unhandled promise rejections
process.on('unhandledRejection', (err) => {
winston.error('Unhandled Rejection:', err)
server.close(() => {
process.exit(1)
})
})
// Graceful shutdown
process.on('SIGTERM', () => {
winston.info('SIGTERM received. Shutting down gracefully...')
server.close(() => {
winston.info('Process terminated')
})
})
process.on('SIGINT', () => {
winston.info('SIGINT received. Shutting down gracefully...')
server.close(() => {
winston.info('Process terminated')
})
})