Node.js Console Output (STDOUT) to File

I solved by rewriting console.log function.  This was the quickest way to convert stdout object to a string without adding another module.

OUTPUT.JS
var fs = require('fs');
var sys = require('sys');
var exec = require('child_process').exec;
        
function puts(error, stdout, stderr){
    var oldWrite = process.stdout.write;
    process.stdout.write = function(d) {
        fs.writeFile('shellOutput.txt', d);
        oldWrite.apply(this, arguments);
    };
    console.log(stdout);
}

exec('ls -al', puts);

TEST
node output.js