-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (22 loc) · 708 Bytes
/
server.js
File metadata and controls
30 lines (22 loc) · 708 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
26
27
28
29
30
const express = require('express');
const app = express();
const fs = require('fs');
const server = require('http').createServer(app);
const io = require('socket.io')(server);
app.use('/', express.static(__dirname + '/build'));
const port = 3000
server.listen(port, () => console.log(`server started on http://localhost:${port}`));
let file = fs.readFileSync(__dirname + '/test/index.js').toString();
io.on('connection', function (socket) {
socket.emit('doc', {
timestamp: new Date().getTime(),
doc: file
})
socket.on('update', function (data) {
file = data.doc;
io.emit('doc', data);
})
socket.on('disconnect', function (data) {
console.log('disconnect', data)
})
});