-
Notifications
You must be signed in to change notification settings - Fork 17
/
server.js
38 lines (27 loc) · 845 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
"use strict";
require('dotenv').config();
const express = require('express');
const http = require('http');
const socketIO = require('socket.io');
const fs = require('fs');
const morgan = require('morgan');
const path = require('path');
const PORT = process.env.PORT || 3000;
const app = express();
app.use(morgan('common'));
app.use(express.static(__dirname + '/public'));
app.use(require('./app/routes'));
const server = http.Server(app);
server.listen(PORT, () => {
console.log(`Server listening on http://localhost:${PORT}`);
});
const io = socketIO(server);
require('./app/socket')(io);
process.on('uncaughtException', (err) => {
shutdown('Uncaught excecption occurred', err);
});
function shutdown(message, err) {
console.log(`${message}: gracefully shutting down...`);
console.error(err);
process.exit(1);
}