-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (26 loc) · 881 Bytes
/
index.js
File metadata and controls
32 lines (26 loc) · 881 Bytes
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
import dotenv from 'dotenv'
import 'express-async-errors'
import app from './app.js'
import dbConnect from '#db'
import { errorHandler } from '#errors'
dotenv.config()
const PORT = process.env.PORT || 8080
// catching error that is thrown in the synchronous part of your application and it's not caught or handled anywhere in the call stack.
process.on('uncaughtException', (err) => {
console.error('UNCAUGHT EXCEPTION! 💥 Shutting down...')
console.error(err.name, err.message)
process.exit(1)
})
dbConnect().then(() => {
const server = app.listen(PORT, () => {
console.log(`Server started on http://localhost:${PORT}`)
})
process.on('unhandledRejection', (err) => {
console.error('UNHANDLED REJECTION! 💥 Shutting down...')
console.error(err.name, err.message)
server.close(() => {
process.exit(1)
})
})
})
app.use(errorHandler)