Execute shell command and get log nodejs

I am using this native nodejs method to run an executable file:

child = exec('node app.js',
function (error, stdout, stderr) {}
});

The callback is invoked when the process terminates. but i need what the process logs in the console during is lifetime. is this possible? thank you!

Use spawn instead. Example:

var cproc = require("child_process");

proc = cproc.spawn("ping", ["www.google.com"]);

proc.stdout.on("data", function(res) { 
        console.log("Data received: " + res);
});