repl.it
@LukeZeller/

Socket Chat

Express

No description

fork
loading
Files
  • index.js
  • icons
  • index.html
  • style.css
  • Packager files
  • package-lock.json
  • package.json
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
31
32
33
34
35
36
37
var app = require('express')();
var http = require('http').createServer(app);
var io = require('socket.io')(http);

app.get('/', function(req, res){
  res.sendFile(__dirname + '/index.html');
});

app.get('/style.css', function(req, res){
  res.sendFile(__dirname + '/style.css');
});

app.get('/icons/send_white.svg', function(req, res){
  res.sendFile(__dirname + '/icons/send_white.svg');
});

app.get('/icons/default_user.svg', function(req, res){
  res.sendFile(__dirname + '/icons/default_user.svg');
});

io.on('connection', function(socket){
  socket.to(socket.id).emit("init", socket.id)
  console.log('[' + socket.id + ']: connected');
  socket.on('disconnect', function(){
    console.log('[' + socket.id + ']: disconnected');
  });
});

io.on('connection', function(socket){
  socket.on('chat message', function(msg){
    io.emit('chat message', msg);
  });
});

http.listen(3000, function(){
  console.log('[server]: listening on *:3000');
});
?