Get Public IP Address for node.js application

Is there any node.js module that can be used to get the public IP address of the client's computer making a request? I don't mean IPv4 or IPv6, I need the public IP like you get when you go to

I have tried req.connection.remoteAddress; but it doesn't return the public IP. It has to be public so I can locate the city based on the IP address.

Thanks :)



I know this old question, but now you can use to get IP. Just send request to and get result.

var http = require('http');
http.get('', function(res){
    res.on('data', function(chunk){
var ip = (req.headers && req.headers['x-forwarded-for'])
         || req.ip 
         || req._remoteAddress 
         || (req.connection && req.connection.remoteAddress);

Here's a packaged called external-ip that can do that for you va npm install external-ip:

var externalip = require('external-ip');
externalip(function (err, ip) {
   console.log(ip); // =>



Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.