-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
34 lines (28 loc) · 965 Bytes
/
server.js
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
/**
* @file server.js
* @summary Creates HTTP server
* @description This file is responsible for connecting to mongoDB, creating an HTTP server and adding routes.
* Server is created by binding express app instance.
* */
const { createServer } = require("http");
const { log } = require("./errors");
const { constants } = require("./config");
const { app } = require("./app");
const { connectToMongoDb } = require("./db");
const { PORT, LOG_LEVELS } = constants;
connectToMongoDb();
const server = createServer(app);
// Event listeners to catch uncaught errors
process.on("unhandledRejection", error => {
log(LOG_LEVELS.ERROR, error.message, { time: new Date() });
process.exit(1);
});
process.on("exit", code => {
console.log(`Exiting with code: ${code}`);
});
server.listen(PORT || 8443, err => {
if (err) {
return console.log(`Something went wrong: \n${err}`);
}
console.log(`Server is listening on port: ${PORT}`);
});