-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (32 loc) · 1.17 KB
/
index.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
/**
* Mocking the global dependencies of the node app.
* TODO: make sure this path reflects the root of the directory we are trying to traverse.
* Answer here: http://stackoverflow.com/a/18721515
*/
var path = require("path");
global.appRoot = path.resolve(__dirname);
var winston = require('./lib/appLogger');
// Port defined
// TODO: add to config.
const PORT = 8080;
// Server start and stop: This is basically the whole program.
if (global.startServer) {
let server = require('./lib/server')
.SERVER
.listen(PORT, (err) => {
if (err) {
return winston.log('error', `Error starting server: ${err}`);
}
console.log(`Server started and listening on port: ${PORT}`);
})
// On error close the program, with a helpful error message.
.on('error', function (err) {
if (err.message.includes('EADDRINUSE')) {
winston.log(`error`, `Port: ${PORT} is in use. Please change the port.`);
}
winston.log('trace', `Failed to start server with:`, err);
server.close(function () {
process.exit(0);
});
});
}