-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
39 lines (27 loc) · 991 Bytes
/
app.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
// This is the main file of our chat app. It initializes a new
// express.js instance, requires the config and routes files
// and listens on a port. Start the application by running
// 'node app.js' in your terminal
// Hello World
var express = require('express'),
http = require('http'),
https = require('https'),
path = require('path');
var app = express();
var ioServer = http.Server(app);
var socket = require('socket.io')(ioServer);
// This is needed if the app is run on heroku:
app.set('port',process.env.PORT || 3000);
// var io = require('socket.io').listen(app.listen(port));
console.log(__dirname)
app.use(express.static(__dirname + '/public'));
socket.on('connect',function(socket){
console.log('got a connection')
socket.on('newChat',function(data){
console.log(data)
socket.broadcast.emit('msg',data)
});
});
ioServer.listen(app.get('port'), function(req,res) {
console.log('Express server listening on port number' + app.get('port'));
});