-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
38 lines (32 loc) · 1.07 KB
/
Copy pathserver.js
File metadata and controls
38 lines (32 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
require('dotenv').config()
const app = require('./src/app')
const sequelize = require('./src/config/database')
const config = require('./src/config/config')
const startServer = async () => {
try {
await sequelize.authenticate()
console.log('Database connection has been established successfully.')
// Force true will drop and recreate tables - use only in development
await sequelize.sync({ force: false })
console.log('Database synchronized')
app.listen(config.port, () => {
console.log(`Server is running on port ${config.port}`)
})
} catch (error) {
console.error('Unable to start the server:', error)
process.exit(1)
}
}
startServer()
// Handle unhandled promise rejections
process.on('unhandledRejection', (err) => {
console.error('UNHANDLED REJECTION! 💥 Shutting down...')
console.error(err.name, err.message)
process.exit(1)
})
// Handle uncaught exceptions
process.on('uncaughtException', (err) => {
console.error('UNCAUGHT EXCEPTION! 💥 Shutting down...')
console.error(err.name, err.message)
process.exit(1)
})