I am looking for the most performant way to to tail a file using Node.js.
There are some libaries that do this, but they seem to use polling as they ask for an interval to check for file changes.
I am wondering if I can just spawn a process that does tail -f and read from the stdout out that process. Does anyone know if the tail -f command on a linux machines uses polling or does it somehow hook into lower level observables? How does tail -f work?
In Node.js, I can do this:
const cp = require('child_process');
module.exports = function(file){
const n = cp.spawn('tail',['-f',file]);
n.on('error', function(err){
console.error(err.stack || err);
});
return n.stdout;
};
but I am wondering if there as a more efficient way to do this