This is not a duplicate of this SO post. That method does not work for me. The output is shown below. I am running a local node server on my MacBook and using chrome to test. I get this output.
undefined | ::1
I am connected to the network and can verify that my browser does have an IP address using zshell on Mac which is actually ( I have hidden the last 3 digits for this post):
100.64.98.xxx
However from my server I do not get a reading.
// derived from SO Post above
function getIP(app) {
app.use((req, res, next) => {
const ip1 = req.headers['x-forwarded-for'];
const ip2 = req.socket.remoteAddress;
const ip = ip1 || ip2;
// undefined | ::1
console.log(ip1 + ' | ' + ip2);
next();
});
}
Sometimes the ordering of middleware seems to effect things, and I'm not sure if this might be the case here.