-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
50 lines (44 loc) · 1.38 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
50
var express = require ('express');
var http = require ('http');
var app = express();
var server = http.createServer(app);
var path =require('path');
var io = require('socket.io')(server);
var bodyParser = require ('body-parser');
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:false}))
app.set('views',path.join(__dirname+'views'));
app.set('view engine','ejs');
app.use('/members',require('./routes/members.js'));
io.on('connection', function(client){
console.log("client connect through web socket");
client.emit('greet',"Hey Hi I have been logged in.");
client.on('disconnect', function(){
console.log("Client disconnect");
})
});
io.on('disconnect', function(){
console.log("scoket disconnect");
})
//catch 404 and forward to error handler and this should be always at bottom of stack
app.use(function(request,response,next){
var err = new Error("Not Found");
err.status = 404;
next(err);
});
//error handler
app.use(function (err,request,response, next){
response.locals.message = err.message;
response.locals.error= err;
response.status (err.status || 500);
response.render("error");
});
/*
app.get('/',function (request,response){
response.sendFile(__dirname+'/public/index.html');
//response.end();
});*/
server.listen(3000 , function (){
console.log("server is listening on port 3000");
});