Skip to content

Instantly share code, notes, and snippets.

@netroy
Forked from MichelBartz/tail-f.js
Created March 12, 2011 21:54
Show Gist options
  • Save netroy/867605 to your computer and use it in GitHub Desktop.
Save netroy/867605 to your computer and use it in GitHub Desktop.
/**
* 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);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment