-
-
Save ThisIsMissEm/436631 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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