0

How can I get client public IP without using any API call or external Node Modules?

I already tried req.ip and req.ips but nothing helped me

1 Answers1

1

I'm answering my own question, Finally, I found a solution to get client Ip without using any modules or any API call

(req.headers['x-forwarded-for'] ||
    req.connection.remoteAddress ||
    req.socket.remoteAddress ||
    req.connection.socket.remoteAddress).split(",")[0];

Above code will return the clients public IP.