title: How to return value from helper function back to server.js NodeJS
body: <p>For my project I have a server.js that calls a helper function place-search.js as shown below.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var express = require('express');
  var server = express.Router();
  
  var placeSearch = require("./helpers/place-search");
  var obj = "hello";
  
  server.use(function(req, res, next) {
   console.log(req.method, req.url);
   next();
  }); 
  
  server.post('/', function(req, res) {
   /* get the object passed by the client's post request */
   obj = req.body;
  
   //console.log("Obj: " + obj);
  
   /* send the confirmation back to the client */
   res.status(200).send("body");
   placeSearch.placeSearch(obj);
  });
  
  module.exports.server = server;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Here is my place-search.js :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var config = require("./config.js");
  var Promise = require('bluebird');
  var DistanceMatrix = require("./distance-matrix.js");
  var GooglePlaces = Promise.promisifyAll(require("googleplaces"));
  var googlePlaces = new GooglePlaces(config.apiKey, config.outputFormat);
  var extract = require('./extract.js');
  var combination = require('./combination_ver2.js');
  var permutation = require('./permutation.js');
  
  function placeSearch(obj) {
  
      console.log("Inside place search!");
  
      /**
       * Place search - https://developers.google.com/places/documentation/#PlaceSearchRequests
       */
      var arr = [];
      var count = 0;
      var rad = obj["radius"];
      
      console.log("radius: " + rad);
      var loc = obj["location"];
      console.log("Location: " + loc);
      var mode = obj["mode"];
  
      var params = obj["params"];
  
      /* client's keywords */
      var arr;
      var ar = [];
      for (var i = 0; i &lt; params; i++) {
          arr[i] = obj[i];
          console.log(arr[i]);
          var param = {
              location: loc,
              radius: rad,
              mode: mode,
              keyword: arr[i]
          };
          ar.push(param);
      }
  
      console.log("before promises");
  
      var promises = ar.map(function(name) {
          return googlePlaces.placeSearch(name, function(response) {
              arr.push(response);
              console.log(response);
              console.log(count++);
              //If all responses have been returned
              //Find combos and pass to distance-matrix
              if (count == ar.length) {
                  var Matrix = new Array();
                  var result = new Array();
  
                  //to extract only lat and lng from arr.results
                  //Matrix = extract.extract(arr);
                  result = combination.combination(arr);
  
                  // NOW RESULT IS THE ARRAY OF ALL COMBINATION
  
                  // NOW RESULT IS THE ARRAY OF COMBINATIONS OF latlng pairs AND PASS IT TO FRONTEND
                  /*result.forEach(function(combo, index) {
                      console.log("combo" + combo)
                      DistanceMatrix.distanceMatrix(mode, combo, result.length);
                  });*/
  
  
                  // IF YOU WANT TO SEE PERMUTATION
                  //permutation.permutation(result);
  
                  console.log("combination results: " + result);
  
              }
  
          })
      });
  
  }
  
  module.exports.placeSearch = placeSearch;</code></pre>
  </div>
  </div>
  </p>
  
  <p>My problem is I do not know how to pass the result variable back to the server.js so that I can use that result as an input for another helper function. I can not for the life of me figure out how to do this. Any help at all would be greatly appreciated.</p>