title: Not able to return value even with callback function
body: <p>I have read the following questions and corresponding insightful answers and understood how asynchronous call back functions work- </p>
  
  <p><a href="https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call">How do I return the response from an asynchronous call?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/6847697/how-to-return-value-from-an-asynchronous-callback-function">How to return value from an asynchronous callback function?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/6211023/returning-value-from-asynchronous-javascript-method">Returning value from asynchronous JavaScript method?</a></p>
  
  <p>But still not able to successfully return the appropriate vaule. Following is the code - </p>
  
  <pre><code>function foo(callback){
      request('some-url.json', function (error, response, body) {
          //Check for error
          if(error){
              //error body
          }
  
          //Check for right status code
          if(response.statusCode !== 200){
              //response body
          }
  
          //All is good. Print the data
          var data = JSON.parse(body);
          callback(data.some-property);
      });
  }
  
  
  module.exports = {
      foo:foo(function(result){
          console.log(result); //works
          return result; //doesn't work
  
      }),
  };
  </code></pre>
  
  <p>I am able to get the expected result in the console log but still its not able to <strong>return</strong> the value.</p>
  
  <p><strong>Error</strong>: <code>TypeError: Property 'foo' of object #&lt;Object&gt; is not a function</code></p>
  
  <p><strong>Problem</strong>: </p>
  
  <p>1.Is the callback function execution correct?</p>
  
  <p>2.What should I do to return the value successfully?</p>
  
  <p><strong>Edit</strong>: Finally after an extensive conversation with Paarth I have decided to resort to promise.js which will allow me to indirectly return the value I seek from my function. For further resources regarding promise.js - </p>
  
  <p><a href="https://gist.github.com/domenic/3889970" rel="nofollow noreferrer">https://gist.github.com/domenic/3889970</a></p>
  
  <p><a href="https://www.promisejs.org/" rel="nofollow noreferrer">https://www.promisejs.org/</a></p>
  
  <p><a href="http://colintoh.com/blog/staying-sane-with-asynchronous-programming-promises-and-generators" rel="nofollow noreferrer">http://colintoh.com/blog/staying-sane-with-asynchronous-programming-promises-and-generators</a></p>
  
  <p>Also worth mentioning : <a href="https://github.com/petkaantonov/bluebird" rel="nofollow noreferrer">Bluebird</a> &amp; <a href="https://github.com/kriskowal/q" rel="nofollow noreferrer">q</a></p>