I'm trying to create a stream of data to the browser using websocket. The data is the output of a log file. (tail -f filename) Using node js, I've manage to log into stdout, but I haven't been able to create the server and create the client (js/html) code to create a websocket and receive all the output of this child process. Can anyone help me?
NODE.JS SERVER OUTPUTTING TAIL TO STDOUT (as seen in http://snippets.dzone.com/posts/show/12067)
var sys = require('sys')
var spawn = require('child_process').spawn;
var filename = process.ARGV[2];
if (!filename)
return sys.puts("Usage: node <server.js> <filename>");
var tail = spawn("tail", ["-f", filename]);
sys.puts("start tailing");
tail.stdout.on("data", function (data) {
sys.puts(data);
});
My goal is to have the simplest stream possible. Any other simple solution is well received for this. Thanks.