title: Using Nodejs, Express and AngularJS to display IP in the browser
body: <p>I'm learning Nodejs and ExpressJS. I'm trying to use ExpressJS and 2 Node modules (<a href="https://www.npmjs.com/package/request-ip" rel="nofollow noreferrer">request-ip</a> and <a href="https://www.npmjs.com/package/geoip2" rel="nofollow noreferrer">geoip2</a>) to get the client IP address for geolocation and then outputting the geolocation in the browser using AngularJS (1.x).</p>
  
  <p>So far for my Nodejs and Expressjs code I have</p>
  
  <pre><code>    var express = require('express');
  // require request-ip and register it as middleware
  var requestIp = require('request-ip');
  // to convert the ip into geolocation coords
  var geoip2 = require('geoip2');
  
  // Init app
  var app = express();
  var port = process.env.PORT || 8000;
  
  geoip2.init(); // init the db
  
  //app.use(requestIp.mw({ attributeName: 'myCustomAttributeName'}));
  var ip = '207.97.227.239';//67.183.57.64, 207.97.227.239
  
  // respond to homepage req
  app.get('/', function (req, res, next) {
      //var ip = req.myCustomAttributeName;// use this for live
      //var ip = '207.97.227.239';/* use this for testing */
      console.log('requestIP is ' + ip);
      next();
      // geolocation
      geoip2.lookupSimple(ip, function(error, result) {
        if (error) {
          console.log("Error: %s", error);
        }
        else if (result) {
          console.log(result);//ipType was causing console.log duplication, IDK why
        }
      });
  });
  
  // set static folder
  app.use('/', express.static(__dirname + '/public'));
  
  app.listen(port, function(){
      console.log('user location app is running');
  });
  </code></pre>
  
  <p>And for Angular I have</p>
  
  <pre><code>angular.module('UserLocation', []);
  
  angular.module('UserLocation')
      .controller('MainController', MainController);
  
  MainController.$inject = ['$http'];
  
  function MainController($http) {
      var vm = this;
      vm.result = '';
  
      vm.message = 'Hello World';
      vm.getLocation = function() {
          console.log();
          return $http.get('localhost:8000', {
          params: {result: result}
        })
        .then(function(result){
          console.log(result);
          })
        }; 
      };
  </code></pre>
  
  <p><code>vm.result</code> in the Angular controller is for the result from the geoip2 Node module that performs the geolocation.</p>
  
  <p>I can get the <code>result</code> in the console no problem but I'm not to sure how to pass it to Angular. I'm using the <code>$http</code> service but I'm not sure where to go from here...?</p>
  
  <p>How do I pass the <code>result</code> from the geoip2 Node module to my Angular controller with $http? </p>