title: Return data from a http request function
body: <p>I been looking to some code now to simplify for days. Tried many options, but I am not able to figure it out.</p>
  
  <p>I want to make an http request by a function and then get the data back to use in another function. My issue is that I cant seem to retrieve the data in another function. The console.log works fine.</p>
  
  <pre><code>function getData() {
      request('http://' + address + ':' + port + '/all.xml', function (err, res) {
          if (err) {
              console.log('ERROR: Unable to get CyberQ Data')
          }
          else {
              console.log(res.body);
              return res.body;
          }
      });
  }
  </code></pre>
  
  <p>The below code is my original code. Also works like a charm, expect the most important part, res.json. I like to send the data back to the browser, but the result is not available in the function at the place I added res.json.</p>
  
  <p>If either of these two pieces of code can work, I can make my code working. I probably overlook something basic. Thanks in advance for any help</p>
  
  <pre><code>router.get('/bbq/cyberqData', function (req, res) {
      request('http://' + address + ':' + port + '/all.xml', function (err, res) {
          if (err) {
              console.log('ERROR: Unable to get CyberQ Data')
          }
          else {
              console.log('getting the data ');
              parseString(res.body, function (err, result) {
                  console.log(result.nutcallstatus);
                  return result;
              });
          }
      });
      res.json(result);
  });
  </code></pre>