问题
I need to read from a stream when my application goes live, but at the moment, i'm just reading from a normal log file (60000+ JSON documents inside).
I will need to read the data received from the last minute(not implemented, since I don't have acess to the stream and can't figure out how to do it), process the data, and ask for more next minute. Any packages or tutorials to help? please
Now I'm using a recursion. that every minute calls the start() function, I'm using the setTimeout function but it doesn't seem right.
app.js:
function start()
{
console.dir(new Date())
cfg.checkDb()
setTimeout(start, 60000);
}
start();
cfg.js:
exports.checkDb = function () {
MongoClient.connect(url, function (err, database) {
db = database;
flags = db.collection('flags');
historico = db.collection('historico');
if (isEmpty(mobile) == true) {
dbToMemory(init);
}
else {
init();
}
})
}
function init() {
fs.readFile('log.log', 'utf8', function (err, source) {
objfile = JSON.parse(source);
searchFilePile(objfile);
})
}
EDIT: The stream come from a server that receives documents from another source, every document comes already in asceding order.
来源:https://stackoverflow.com/questions/32206017/node-js-stream-timer-recursion