-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (46 loc) · 1.73 KB
/
Copy pathserver.js
File metadata and controls
49 lines (46 loc) · 1.73 KB
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
'use strict';
var express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var bodyParser = require('body-parser');
var mongoose = require('mongoose'); // mongoose for mongodb
var morgan = require('morgan'); // log requests to the console (express4)
// var bodyParser = require('body-parser'); // pull information from HTML POST (express4)
var methodOverride = require('method-override'); // simulate DELETE and PUT (express4)
mongoose.connect('mongodb://pratyush1995:chunmun1998@ds153735.mlab.com:53735/chit0chat');
var Cat = mongoose.model('Cat',{name:String});
var kitty = new Cat({name:'eshita'});
kitty.save();
app.get('/', function (req, res) {
// res.send('Hello World!');
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket) {
// console.log(socket.server.eio.clients);
// var temp = JSON.parse(socket);
// console.log(temp);
// console.log(socket.id);
// var tweet={'user':socket.server.eio.clients};
// io.emit('check',tweet);
io.emit('clientCount',socket.server.eio.clientsCount);
// io.emit('clientCount',socket.server.eio.clientsCount);
socket.on('message',function(msg){
console.log(msg);
io.emit('messageAll',msg);
})
socket.on('typing',function(type){
io.emit('typeAll',type);
})
socket.on('disconnect', function() {
console.log('disconnected');
});
// socket.send('welcome to the local node.js server!');
});
app.use(express.static(__dirname));
app.use(express.static(__dirname + '/chat'));
server.listen(process.env.PORT || 5000);
// io.on('connection',function(socket){
// console.log('user connected');
// })
// var socket = io.listen(server);