I have tried using the following approach but when hosted the application . I'm getting the ip address that the application us hosted on. Also I have used req.ip and req.socket.remoteAddress but it was returning the local host ip I.e ,::1
here is what I tried.
var express = require('express');
var request = require('request');
var app = express();
const IPData = require("ipdata").default;
require('dotenv').config();
const apiKey = process.env.API_KEY;
const ipdata = new IPData(apiKey);
app.get('/location', async (req, res) => {
    try{
        request.get('http://ipinfo.io/ip', (error, response, body) => {
            if (!error && response.statusCode == 200) {
                let clientIp = req.headers["x-forward-ip"] || body
                console.log(body);
                ipdata.lookup(clientIp)
                    .then((data) => {
                        console.log(data);
                        return res.json({
                            city: data.city,
                            region: data.region,
                            country: data.country_name,
                            postal: data.postal
                        });
                    })
                    .catch((error) => {
                        console.log(error);
                        res.status(500).send('Error looking up location');
                    });
            }
        });
    }catch(error) {
        console.log(error);
        res.status(500).send('Error looking up location');
    }
   
});
app.listen(8000, () => {
    console.log('Server started on port 8000');
});
 
     
    