-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (26 loc) · 1.03 KB
/
index.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
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var path = require('path');
// Initialize appication with route / (that means root of the application)
app.get('/', function(req, res){
var express=require('express');
app.use(express.static(path.join(__dirname)));
res.sendFile(path.join(__dirname, '../nodejschat', 'index.html'));
});
// Register events on socket connection
io.on('connection', function(socket){
socket.on('chatMessage', function(from, msg){
io.emit('chatMessage', from, msg);
});
socket.on('notifyUser', function(user, mmm){
io.emit('notifyUser', user, mmm);
});
});
// Listen application request on port 3000
// http.listen(3000, function(){
// console.log('listening on *:3000');
// });
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080; // Port 8080 if you run locally
var address = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1"; // Listening to localhost if you run locally
app.listen(port, address);