/** * A `tail -f` implementation in Node.js. * * Original author : Bratish Goswami <bratishgoswami AT gmail DOT com> * Modified by : Michel Bartz <michel.bartz AT manwin DOT com> * */ var sys = require("sys"), fs = require('fs'), f = "/path/to/file"; fs.watchFile(f, function(curr, prev) { if(prev.size > curr.size){ // probably file is overwritten, seek on the stream will fail return; } fs.createReadStream(f, { start: prev.size, end: curr.size}).addListener("data", function(lines) { sys.log(lines); }); });