I'm working on a project which requires reading a log file, The log file can get massive, so I only want to read additional data added to the file and not the old data to avoid potential performance issues.
I tried fs.createReadStream but it didn't seem to work:
code:
let stream = fs.createReadStream(`/path/`, { autoClose: true, encoding: "utf-8" });
stream.on('ready', () => {
console.log("Loaded log file!");
})
stream.on("data", chunk => {
// Data stream
});
stream.on("end", () => {
stream.pause();
console.log("ended");
// Going thru the data
setTimeout(() => {
stream.resume();
stream.read();
}, 10000);
});
With that code, the "end" event only triggers once, although the stream is set to not close automatically, and no additional data is going thru.