title: HTTP GET inside a api method called by the client
body: <p>Hi I have a rest api set up in Nodejs and the ajax call is working perfectly, that is until I try to call an external REST service from within the method.</p>
  
  <p>Can anyone help me out to work out why this wont work? I'm using Nodejs with Express running on port 3000, basically localhost at the minute. Bellows my work in progress but its been changed alot. I was using the request module but now have went back to http.</p>
  
  <pre><code>app.get('/api/exchange', function (req, res){
      var text = '';
      var options = {
          host : 'rate-exchange.appspot.com',
          port : 3000,
          path : '/currency?from=GBP&amp;to=USD',
          method : 'GET'
      };
  
      var call = http.request(options, function(res) {
          console.log("statusCode: ", res.statusCode);
          text = "made it in";
  
          res.on('data', function(d) {
              text = "here";
          });
      });
  
      call.end();
      call.on('error', function(e) {
          text = "error";
      });
  
      res.json({ msg: text });
  });
  </code></pre>
  
  <p>Excuse my <code>classic javascript debuging technique</code>, I'm basically just using <code>text</code> to see where its going. </p>
  
  <p>When I run this I get the following back.</p>
  
  <pre><code>{
      "msg": ""
  }
  </code></pre>
  
  <p>p.s. anyone knows of any good debuging tools for node I'd be greatful.</p>