-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.ts
37 lines (28 loc) · 892 Bytes
/
Server.ts
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
// configuration intializer for nconf
import setupConfiguration from './src/configuration';
setupConfiguration();
import http from 'http';
import log4js from 'log4js';
import mongoose from 'mongoose';
import nconf from 'nconf';
import app from './src/app';
import setupLogger from './src/setup/Logger';
import setupMongoose from './src/setup/DB';
setupLogger();
setupMongoose();
const logger = log4js.getLogger('setup:server');
const PORT = nconf.get('configuration:server:port');
const server = http.createServer(app).listen(PORT, (error: Error) => {
if (error) {
logger.error(`Error occurs during server start up. ${error}`);
} else {
logger.info(`The server is listening on port: ${PORT}`);
}
});
server.on('close', async () => {
await mongoose.connection.close();
});
process.on('SIGINT', async () => {
await mongoose.connection.close();
process.exit(0);
});