NEED HELP with API project request header parser microservice

I have been following similar procedures taught by this youtuber from freeCodeCamp:

I first use Mac terminal and sublime text 3 to use npm and code, then I deploy to heroku.

var express = require("express");
var router = express.Router();
var requestIP = require("request-ip")
/* GET home page. */
router.get('/', function(req, res) {
  var language = req.headers['accept-language'].split(",")[0]
  var software = req.headers['user-agent'].match(/\((.+?)\)/)[1]
  var ip = requestIP.getClientIp(req)
  var result = {'ipaddress' : req.ip ,'Language' : language, 'software': software };
module.exports = router;

I was able to extract software detail and language property from the request header, but I just couldn’t extract the IP address at all.
Both req.ip and request-ip module and its method doesnt return a correctly formatted ip-address. It shows something like this:

Please advise, any kind souls?

This is the url of my project in heroku:
This is the github repo of my project:


The IP address returned is actually the equivalent IPv4 address converted to an IPv6 address. IPv6 comes into play because we ran out of numbers. :slight_smile:

Please see this more informative response from Nick (Stackoverflow)

In my opinion, you can display either ::ffff:<IPv4 address> or just the <IPv4 address>

1 Like

Hi Russell, thank you so much for the response. Another question: the IPv4 address number returned by the program I wrote is different from the sample programme given in the project description page:

Any idea why this is so?

Interesting. I just checked my own solution and it behaves the same way meaning that I’ll have to change it. Thanks :slight_smile:

The 10...* address range is reserved for private networks, so Heroku is doing some internal routing.

Have a look at the X-Forwarded-For header and see if you can find the correct address from there.

Also, see for Express specific information.

1 Like