-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
49 lines (37 loc) · 1.26 KB
/
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
44
45
46
47
48
49
const express = require('express');
const path = __dirname + '/client/';
var app = express();
var http = require('http').Server(app);
var ioClient = require('socket.io')(http);
var clients = [];
var port = 80;
const bp = require('body-parser');
app.use(bp.json())
app.use(bp.urlencoded({ extended: true }))
// Search for argument port= in node cli arguments
process.argv.forEach(arg => {
if(arg.startsWith("port=")){
var reqPort = arg.slice(arg.indexOf("=") + 1);
reqPort = Number.parseInt(reqPort);
// check validity of requested port
if(reqPort >= 0 && reqPort <= 65353) port = reqPort;
else console.log(arg + " doesn't include a valid port number, using default port instead: " + port);
}
});
port = process.env.PORT || port;
app.use(express.static(__dirname + '/client/'));
var events = require('events');
const { NONAME } = require('dns');
var eventEmitter = new events.EventEmitter();
ioClient.on('connection', function(socket){
console.log('user connected');
socket.on('disconnect', function(msg){
console.log('user disconnected');
});
});
app.get('/', function(req, res){
res.sendFile(path + 'index.html')
});
http.listen(port, function(){
console.log('listening on *:' + port);
});