title: Node.js spawn child process and get terminal output live
body: <p>I have a script that outputs 'hi', sleeps for a second, outputs 'hi', sleeps for 1 second, and so on and so forth. Now I thought I would be able to tackle this problem with this model.</p>
  
  <pre><code>var spawn = require('child_process').spawn,
  temp    = spawn('PATH TO SCRIPT WITH THE ABOVE BEHAVIOUR');
  
  temp.stdout.pipe(process.stdout);
  </code></pre>
  
  <p>Now the problem is that the task needs to be finished in order for the output to be displayed. As I am understanding it, this is due to the fact that the newly spawned process takes execution control. Obviously node.js does not support threads so any solutions? My idea was to possibly run two instances, first one for the specific purpose of creating the task and have it pipe the output to process of the second instance, considering this can be achieved.</p>