title: How to GET JSON Object from URL in Node.js/Express
body: <p>I should preface my post by saying that I am a beginner and this is my first time using Node.js and Express in a real project.</p>
  
  <p>I have a simple Node.js/Express project and I want to read a JSON object from a URL. Afterwards, I intend to build another url that displays html from an external website using iframe.</p>
  
  <p>I read about the 'request' module online and know that I need to do something along these lines:</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  var request = require('request');
  
  // Urls for App Center REST functions
  var url = 'https://someserver.com/appserver/portal/api/1.0/results/recent';
  
  /* GET list of recent reports */
  router.get('/testapi', function(req, res, next) {
    res.render('testapi', { title: 'List Recent Reports' });
  });
  
  /* TEST: function to GET report list */
  router.get('/recentreports', function(req, res){
    request({
      url: url,
      json: true
    }, function (error, response, body) {
        if (!error &amp;&amp; response.statusCode === 200) {
          console.log(body) // Print the json response
      }
    })
  });
  </code></pre>
  
  <p>I have tried to define a function <code>/recentreports</code> which is called in the <code>testapi.jade</code> view, however nothing is printed in the console when I load the page and I suspect I am doing something horribly wrong.</p>
  
  <p>My questions are:</p>
  
  <ol>
  <li><p>How do I read the JSON into my app and where does this code go (index.js, app.js, testview.jade etc...?)</p></li>
  <li><p>How do I export the URL I construct from wherever that code lives to my .jade view?</p></li>
  </ol>