title: How to use ipinfo.io in Node.js and Express (and Heroku) application properly
body: <p>I want to block users from some specific countries, and found that ipinfo.io serves the purpose. But when I tried to use it in my Node.js and Express application, it looks like it didn't return a correct result.</p>
  
  <p>Here's the code that I wrote:</p>
  
  <pre><code>
  var request = require("request");
  
  exports.index = function(req, res) {
      request.get("http://ipinfo.io/" + req.ip + "/json", function(err, response, body) {
          res.write(body);
          res.end()
      });
  }
  
  exports.index2 = function(req, res) {
      request.get("http://ipinfo.io/json", function(err, response, body) {
          res.write(body);
          res.end();
      });
  }
  </code></pre>
  
  <p>And I conencted those two functions above to each specific route, say, <code>http://myapp/index1</code> and <code>http://myapp/index2</code>. However, when I tried to access <code>http://myapp/index1</code>, the result is something like follows:</p>
  
  <pre><code>{
    "ip": "10.xxx.xx.xx", # BTW, is this ip secure information?
    "hostname": "No Hostname",
    "loc": "",
    "bogon": true
  }
  </code></pre>
  
  <p>So it doesn't return a correct value.</p>
  
  <p>When I tried to access <code>http://myapp/index2</code>, the result is an IP on AWS, since Heroku uses AWS in its background.</p>
  
  <p>So how can I have it return a proper result?</p>