Skip to content

Instantly share code, notes, and snippets.

@ThisIsMissEm
Forked from anonymous/gist:436620
Created June 13, 2010 12:38
Show Gist options
  • Save ThisIsMissEm/436631 to your computer and use it in GitHub Desktop.
Save ThisIsMissEm/436631 to your computer and use it in GitHub Desktop.
var sys = require('sys')
, http = require("http")
, spawn = require('child_process').spawn;
var filename = process.ARGV[2];
if (!filename){
sys.puts("Usage: node watcher.js filename");
process.exit(1);
} else {
var tail = spawn("tail", ["-f", filename]);
sys.puts("start tailing");
http.createServer(function(req, res) {
tail.stdout.addListener('data', function(data) {
res.writeHead(200, {
'Content-Length': data.length,
'Content-Type': 'text/plain'
});
sys.puts("add listener called in server");
res.write(data);
// you can actually do res.end(data);
res.end();
});
}).listen(8080);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment