我有这个程序:
var planetStream = require('../../');
var app = require('http').createServer(handler);
var io = require('socket.io')(app);
var fs = require('fs');
app.listen(8000);
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
var diffs = planetStream();
var buildings = diffs
.map(JSON.parse)
.filter(function (x) {
return x.action === 'create' && x.type === 'way' &&
x.tags.building;
});
buildings.onValue(function (x) {
console.log(x);
io.emit('buildings', x);
});
对于数据监控,我需要将其通过管道传送到热衷的 io 中。有人知道如何做到这一点或以前做过吗?
带着敬意
安德烈