title: Sending data from Sails Service to a Controller
body: <p>I'm writing a pretty basic HTTP request using SailsJS. I'm getting the data I want from the api that I'm calling, but I can't figure out how to pass it from my service back to the controller and eventually respond to the request with the data in the body. </p>
  
  <p>Here's my controller:</p>
  
  <pre><code>module.exports = {
      retrieve: function(req, res) {
          var output = AccountService.retrieveAccountInfo();
          console.log(output);
          return res.send(output);
      }
  }
  </code></pre>
  
  <p>And here is my service that I'm calling. </p>
  
  <pre><code>module.exports = {
  
      retrieveAccountInfo: function() {
          var http = require('http');
  
          var options = {
              host: 'localhost',
              port: 8280,
              path: '/sample/account?id=1',
              method: 'GET',
              headers: {
                  'sample': 'header'
              }
          };
  
          var req = http.request(options, function(res) {
              var data = '';
              console.log('STATUS: ' + res.statusCode);
              console.log('HEADERS: ' + JSON.stringify(res.headers) + '\n\n');
              res.setEncoding('utf8');
              res.on('data', function(chunk) {
                  console.log('BODY: ' + chunk);
                  data += chunk;
              });
  
              res.on('end', function() {
                  console.log('hit the end');
                  return JSON.stringify(data);
              });
          });
  
          req.on('error', function(e) {
              console.log('problem with request: ' + e.message);
          });
  
          req.end();
      }
  }
  </code></pre>
  
  <p>I'm probably missing some basic JavaScript stuff here. I can get to the end callback and print "hit the end" as expected, but I can't get the data returned to the controller.</p>