-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (24 loc) · 758 Bytes
/
server.js
File metadata and controls
33 lines (24 loc) · 758 Bytes
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
var express = require('express'),
app = express(),
http = require('http').Server(app),
bodyParser = require('body-parser'),
//io = require('socket.io')(http),
path = require('path'),
fs = require('fs'),
SERVER_PORT = 3000;
// parse json
app.use(bodyParser.json());
// Define route: static
app.use(express.static(path.join(__dirname, '.')));
// start listening
http.on('error', function(err){
if(err.code === 'EADDRINUSE'){
console.log('Port '+SERVER_PORT+' already in use, trying '+(SERVER_PORT+1)+'...');
SERVER_SERVER_PORT++;
http.listen(SERVER_PORT);
}
});
http.on('listening', function(){
console.log('Server ready at http://localhost:'+SERVER_PORT);
})
http.listen(SERVER_PORT);