-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (27 loc) · 785 Bytes
/
server.js
File metadata and controls
41 lines (27 loc) · 785 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
33
34
35
36
const app = require("./app")
const connectDB = require('./config/db');
const attachChatApp= require("./utils/webSockets");
const main = async ()=>{
//Connect to database
await connectDB();
// Websockets setup
const server = attachChatApp(app);
// Return after setup
return server;
}
main().then((server)=>{
//access env vars
const PORT = process.env.PORT || 5000;
server.listen(PORT,()=>{
console.log(
`The server is running in ${process.env.NODE_ENV} mode on port ${PORT}`
.brightBlue.bold
)
})
//Handle unhandled promise rejections
process.on('unhandledRejection', (err, promise) => {
console.log(`Error: ${err.message}`.red.bold.underline);
//close server and exit process
server.close(() => process.exit(1));
});
})