title: NodeJS, return from callback in callback in callback
body: <p>I am having issues getting the value returned from a function nested in a function from another function. The code is pretty complicated, but i mocked up something here:</p>
  
  <pre><code>var request = require('request');
  var _url = 'test.com/data/data.json';
  
  function getValue() {
    var val = 0;
    return callFromURL(function(result){
      if(result) {
        // Do stuff...
  
        console.log(result); //Returns a value
        return result;
      }
    })
  }
  
  function callFromURL(callback) {
    request(_url, function (error, response, body) {
          if (!error &amp;&amp; response.statusCode === 200) {
              var service = JSON.parse(body);
              return callback(service);
          } else {
              log.error(error);
              return callback(null);
          }
      });
  }
  
  
  function test() {
    getValue(); //returns undefined
  }
  </code></pre>
  
  <p>When i step through using a debugger or <code>console.log</code> statements I see that the inner return in the callback passed to callFromURL is not undefined, but the result of <code>return callbackFromURL</code> is <code>undefined</code>. How can I correctly return <code>result</code> from the <code>getValue()</code> function in this example?</p>