Over a million developers have joined DZone.

Tail Log Output With Node.js

·
Need some tail look output for your metrics?  For Node.js, here's your solution, straight from Lance Pollard
// http://nodejs.org/api.html#_child_processes
var sys = require('sys')
var spawn = require('child_process').spawn;
var filename = process.ARGV[2];

if (!filename)
  return sys.puts("Usage: node  ");

var tail = spawn("tail", ["-f", filename]);
sys.puts("start tailing");

tail.stdout.on("data", function (data) {
  sys.puts(data);
});

// node tail.js development.log
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}