7 var app
= require('../app');
8 var http
= require('http');
11 * Get port from environment and store in Express.
14 let port
= normalizePort(process
.env
.PORT
|| '3000');
15 app
.set('port', port
);
21 let server
= http
.createServer(app
);
27 var cron
= require('node-cron');
28 var UserModel
= require("../models/user");
29 cron
.schedule('0 0 0 * * *', function() {
30 // Remove unlogged users every 24h
31 UserModel
.cleanUsersDb();
35 * Listen on provided port, on all network interfaces.
39 server
.on('error', onError
);
40 server
.on('listening', onListening
);
41 let io
= require('socket.io').listen(server
); //sockets too
42 //https://stackoverflow.com/a/24610678/4640434
48 require('../sockets')(io
);
51 * Normalize a port into a number, string, or false.
54 function normalizePort(val
)
56 let port
= parseInt(val
, 10);
58 if (isNaN(port
)) // named pipe
61 if (port
>= 0) // port number
68 * Event listener for HTTP server "error" event.
71 function onError(error
)
73 if (error
.syscall
!== 'listen')
76 let bind
= typeof port
=== 'string'
80 // handle specific listen errors with friendly messages
84 console
.error(bind
+ ' requires elevated privileges');
88 console
.error(bind
+ ' is already in use');
97 * Event listener for HTTP server "listening" event.
100 function onListening()
102 let addr
= server
.address();
103 let bind
= typeof addr
=== 'string'
105 : 'port ' + addr
.port
;
106 console
.log('Listening on ' + bind
);