-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
25 lines (20 loc) · 656 Bytes
/
app.js
File metadata and controls
25 lines (20 loc) · 656 Bytes
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
const express = require('express');
const socket = require('socket.io');
const app = express();
var port = process.env.PORT || 3000;
//listen to port
const server = app.listen(port);
const io = socket(server);
///serve static files:-
app.use(express.static('public'));
app.use('/favicon.ico', express.static('images/favicon.ico'));
io.on('connection', function(socket) {
socket.on('chat message', function(data) {
console.log(data);
///recieved message from user now Spread the message;
io.sockets.emit('new', data);
})
socket.on('typing', function(userName) {
io.sockets.emit('typing', userName);
})
})