-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (26 loc) · 820 Bytes
/
Copy pathindex.js
File metadata and controls
35 lines (26 loc) · 820 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
31
32
33
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var fs = require('fs');
app.use(express.static(__dirname + '/node_modules'));
app.use(express.static(__dirname + '/src'));
app.get('/', function(req, res,next) {
res.sendFile(__dirname + '/index.html');
});
server.listen(3000, function () {
console.log('web sockets in da house!');
});
fs.watchFile('data.json', function (curr, prev) {
fs.readFile('data.json', 'utf8', function (err, data) {
if(err) throw err;
io.sockets.emit('stock.data', data);
});
});
io.on('connection', function (socket) {
console.log('user connected');
fs.readFile('data.json', 'utf8', function (err, data) {
if(err) throw err;
socket.emit('stock.data', data);
});
});