Node.js equivalent of cat -n or nl
It seems you need through and split to do the piping right. You do not need sprintf as you could build the number formatting yourself. You also do not need fs, you do not use it anywhere.

Something like

var through = require('through');
var split = require('split');

var linenum = 0;

function alignRight( s, n )
{
  s = s + "";
  return s.length &gt; n ? s : new Array( n - s.length + 1 ).join(" ") + s;
}

var number = through(function (line) {
  this.queue( alignRight( ++linenum, 6 ) + "\t" + line + "\n"  );
});

process.stdin.pipe(split()).pipe(number).pipe(process.stdout);


Does the trick for me. While it seems overkill, the nice thing is that you can pipe data between functions yourself, not needing to rely on the OS shell.