7 const app
= require('../app');
8 const http
= require('http');
11 * Get port from environment and store in Express.
14 const port
= normalizePort(process
.env
.PORT
|| '3000');
15 app
.set('port', port
);
21 const server
= http
.createServer(app
);
27 const cron
= require('node-cron');
28 const 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 const io
= require('socket.io')(server
);
47 require('../sockets')(io
);
50 * Normalize a port into a number, string, or false.
53 function normalizePort(val
)
55 const port
= parseInt(val
, 10);
57 if (isNaN(port
)) // named pipe
60 if (port
>= 0) // port number
67 * Event listener for HTTP server "error" event.
70 function onError(error
)
72 if (error
.syscall
!== 'listen')
75 const bind
= typeof port
=== 'string'
79 // handle specific listen errors with friendly messages
83 console
.error(bind
+ ' requires elevated privileges');
87 console
.error(bind
+ ' is already in use');
96 * Event listener for HTTP server "listening" event.
99 function onListening()
101 const addr
= server
.address();
102 const bind
= typeof addr
=== 'string'
104 : 'port ' + addr
.port
;
105 console
.log('Listening on ' + bind
);