-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·43 lines (33 loc) · 1001 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
35
36
37
38
39
40
41
42
43
import debugLib from 'debug';
import http from 'http';
import express from 'express';
import { config } from './config';
import runLoaders from './loaders';
async function startTheServer() {
const app = express();
const debug = debugLib('app:server');
debug('Starting app server');
await runLoaders(app);
const server = http.createServer(app);
server.listen(config.node.PORT);
server.on('listening', () => {
console.log(`Server started and listening on port ${config.node.PORT}`);
});
server.on('error', error => {
const port = config.node.PORT;
switch (error.code) {
case 'EACCES':
console.error(`Port ${port} requires elevated privileges`);
process.exit(1);
break;
case 'EADDRINUSE':
console.error(`Port ${port} is already in use`);
process.exit(1);
break;
default:
console.error(`Port ${port} received error code ${error.code}`);
throw error;
}
});
}
startTheServer();