title: Sharing Child Process's results with other route in Express and Angular Controller
body: <p>So I am working with Node.js, Express.js, and Angular.js. What I want to do is take the result of a child process , pass that to a route, and then have Angular perform a get request to get that data. </p>
  
  <p>I have looked around, but most of the answers I have seen have been on database connections and requests.</p>
  
  <p>The route that I was going to POST to is just a normal Express.js route. </p>
  
  <p>Here is my code:
  Index.js:</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  var spawn = require('child-process-promise').spawn;
  var data = '';
  
  /* GET  */
  router.get('/', function(req, res, next) {
  res.render('index');
     });
  
   /* POST  */
  router.post('/', function(req, res, next) {
  
  /* Arguements from the clients request body */
  
  /* Child process to run python scripts wrapped in Promise to 
  run the scripts in a synchronous form
   */
  
  /* Script and taking in arguments*/
  spawn('python',["public/model/model.py",'input1','input2']).progress(function(childProcess){
  
      /* Response to the data that is received */
          childProcess.stdout.on('data',function(data){
              data = data.toString();
          });
          /* Prints Error Message */
          childProcess.stderr.on('data',function(data){
              console.log(data.toString());
          });
  
      }).fail(function(err){
          console.error(err);
      });
  
     });
  
    module.exports = router;
  </code></pre>
  
  <p>Here is angular code:</p>
  
  <pre><code>var app = angular.module('ecbc',
  ['ui.router',
  "oc.lazyLoad",
  "highcharts-ng"
  
  ]);
  
  app.config(
  function($stateProvider,$urlRouterProvider){
  
      $urlRouterProvider.otherwise('/');  
  
      $stateProvider      
      .state('input', {
          url:'/',
          templateUrl: 'templates/input.html',
          controller: 'InputController'
      })
  
      .state('descriptive', {
              url: '/descriptive',
              templateUrl: 'templates/descriptive.html',
              controller:'descriptiveController'
          });
  
  });
  
  
  app.controller("ecbcInputController",function($scope,$ocLazyLoad,$http){
  //This is a ng-click event
  $scope.grabPostData = function(){
      $http.get('/data').success(function(data){
          console.log(data);
        });
    };
    });
  </code></pre>