node.js - Need to parse live json file using Socket io -


first heads up! new world of node.js , socket.io have json file contains following data example:-

{ "football": {              "id": 1,             "home": "liverpool",             "away": "chelsea",             "score": "1-0",             "last scorer":"gerrard"              } } 

this file updated live on few seconds basis.

what want achieve parse json , update same html on client side, in addition want listen changes in json file , update same again html client side. how can achieve this, sorry if question seemed dumb enough, suggestion can help.

(sorry little-detailed answer, i'm having computer problems , it's hard much; i'll edit after they're resolved , stops crashing)

to change in file, try like: monitor file change through ajax, how? or check if file has changed using html5 file api

server file:

var eventemitter = require('events').eventemitter; var footballwatcher = new eventemitter();  io.on('connection', function (client) {  // //existing code //  //node.js event listener: footballwatcher.on('update', function(){     io.emit('footballupdate', footballdata); });  //code change in file, use in it: if(updated){     footballwatcher.emit('update');         }); 

client file:

// //existing code (connections, methods, emits , responses, etc.) //  socket.on('football', function(footballjsondata){     //json interpretation }); 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -