-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (24 loc) · 927 Bytes
/
Copy pathserver.js
File metadata and controls
32 lines (24 loc) · 927 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
const app = require('./app')
const connectDatabase = require('./config/database')
const dotenv = require('dotenv');
//Handle the uncaught exceptions Like Varibale a is not defined
process.on('uncaughtException', err => {
console.log(`ERROR: ${err.message}`); //To print the complete error stack err.stack
console.log('Shutting down due to uncaught exception');
process.exit(1);
})
// Setting up config file
dotenv.config({path: 'config/config.env'})
//Connecting to database
connectDatabase();
const server = app.listen(process.env.PORT, () => {
console.log(`Server started on PORT : ${process.env.PORT} in ${process.env.NODE_ENV} mode`)
})
//Handle unhandled promise rejections
process.on('unhandledRejection', err => {
console.log(`ERROR: ${err.message}`);
console.log('Shutting down the server due to Unhandled promise rejection');
server.close(() => {
process.exit(1);
})
})