I want to pass GET value from URL to socket.io so it can emit to front-end. I have this:
app.get('/data/', function (req, res) {
var queryData = url.parse(req.url, true).query;
res.send('Temp: '+queryData.temp);
var temp = queryData.temp; //<= this value I want to send
});
and this:
io.sockets.on('connection', function (socket) {
socket.emit('message', temp); //<= here I want to put data
});
Idea is: make GET requests with some value (example.com/data/?temp=22), pass that value to index.html in real-time (so I can put in graph).
EDIT: I have semi-working solution:
io.sockets.on('connection', function (socket) {
app.get('/data/', function (req, res) {
var queryData = url.parse(req.url, true).query;
res.send('Temp: '+queryData.temp);
var temp = queryData.temp;
socket.emit('message', temp);
}); //app.get data
});
This working form time to time, not always. Sometime works great, sometime not at all. But it is what I want... only to work always.