title: How to capture response from child process in nodejs
body: <p>I am trying to capture some response from my child process in master process. I can log information of child process in master process but unable to capture some return xyz response .
  Here is code for master process: </p>
  
  <pre><code>var express  = require('express');
  var app = express();
  const
               fs = require('fs'),
               cp = require('child_process');
   app.get('/',onRequest );
      function onRequest(request, response) {
                  var express  = require('express');
               var app = express();
  
              var child= cp.spawn('node' ,['./child_process/block.js'],filestreamCallback);
              child.stdout.on('data', function(data) {
                  console.log('stdout: ==== ' + data);
              });
              child.stderr.on('data', function(data) {
                  console.log('stdout: ' + data);
              });
              child.on('close', function(code) {
                  console.log('closing code: ' + code);
              });
          function filestreamCallback() {
                  response.writeHead(200, {'Content-Type': 'text/plain'});
                  baflog.info("Reading Stream completed");
                  response.write('Thanks for Your patience!\n');
                  response.end();
              }
          }
          app.listen(5000);
          console.log('Server started');
  
  Child process : block.js
  
          /*Keep waiting for 10 seconds*/
  
      console.log("Waiting for child Process (block.js) to complete......");
      var startTime = new Date().getTime();
      while (new Date().getTime() &lt; startTime + 10000);
      ret_resp();
      var response = {status:'success'};
      function ret_resp(){
          return response;
      }
      console.log("Thank You for waiting......");
  </code></pre>
  
  <p>Like in console i see output as : 
  stdout====:  Waiting for child Process (block.js) to complete......
   -punws-sohan</p>
  
  <p>stdout: ====  Thank You for waiting......</p>
  
  <p>I cannot see output for return response statement 
  Can anyone suggest how to capture response from child process?</p>