title: Run child processes on cloud foundry node.js
body: <p>Has anyone tried to run child processes on <strong>Cloud Foundry's node.js</strong>?</p>
  
  <p>I have below code running fine locally:</p>
  
  <pre><code>var port = (process.env.VMC_APP_PORT || 3000),
      host = (process.env.VCAP_APP_HOST || 'localhost'),
      http = require('http');
  
  
   var childProcess = require('child_process'),
           phantom = require('phantomjs'),
       ls;
  
   http.createServer(function(req, res) {
  
      ls = childProcess.exec('phantomjs -h', function (error, stdout, stderr) {
      if (error) {
       console.log(error.stack);
       console.log('Error code: '+error.code);
       console.log('Signal received: '+error.signal);
      }
      console.log('Child Process STDOUT: '+stdout);
      console.log('Child Process STDERR: '+stderr);
      });
  
      ls.on('exit', function (code) {
          console.log('Child process exited with exit code '+code);
        res.writeHead(200, {'Content-Type': 'text/plain'});
        res.write('Working...');
        res.end();
      });
  
   }).listen(port, host);
  </code></pre>
  
  <p>But <code>vmc push</code> on <strong>cloudfoundry.com</strong>, it gave me error in <code>vmc logs</code></p>
  
  <pre><code>Reading logs/stdout.log... OK
  Child process exited with exit code 127
  Error: Command failed: /bin/sh: phantomjs: not found
  
      at ChildProcess.exithandler (child_process.js:536:15)
      at ChildProcess.EventEmitter.emit (events.js:91:17)
      at maybeClose (child_process.js:634:16)
      at Socket.ChildProcess.spawn.stdin (child_process.js:805:11)
      at Socket.EventEmitter.emit (events.js:88:17)
      at Socket._destroy.destroyed (net.js:358:10)
      at process.startup.processNextTick.process._tickCallback (node.js:244:9)
  Error code: 127
  Signal received: null
  Child Process STDOUT:
  Child Process STDERR: /bin/sh: phantomjs: not found
  
  Child process exited with exit code 127
  Error: Command failed: /bin/sh: phantomjs: not found
  
      at ChildProcess.exithandler (child_process.js:536:15)
      at ChildProcess.EventEmitter.emit (events.js:91:17)
      at maybeClose (child_process.js:634:16)
      at Socket.ChildProcess.spawn.stdin (child_process.js:805:11)
      at Socket.EventEmitter.emit (events.js:88:17)
      at Socket._destroy.destroyed (net.js:358:10)
      at process.startup.processNextTick.process._tickCallback (node.js:244:9)
  Error code: 127
  Signal received: null
  Child Process STDOUT:
  Child Process STDERR: /bin/sh: phantomjs: not found
  </code></pre>
  
  <p>Then I also added <code>package.json</code> file below and still same error:</p>
  
  <pre><code>{
    "name" : "mytestchildprocesses",
    "version" : "0.1.0",
    "dependencies" : {
      "phantomjs" : "1.8.1-3",
      "child_process" : "0.x.x",
      "http" : "0.0.0"
    }
  }
  </code></pre>
  
  <p>Alternatively, I tried someone else work on putting phantomjs on node.js: <a href="https://github.com/sgentle/phantomjs-node" rel="nofollow">https://github.com/sgentle/phantomjs-node</a>. But this option doesn't even work on my local machine (could not call phantomjs.cmd in Windows).</p>
  
  <p>I rather figured out how to do child processes in cloudfoundry.com if you guys can help.</p>
  
  <p>Really appreciate!!</p>