Difference of different way of getting ip address

Difference of different way of getting ip address
0.0 0

#1

I am trying to get the ip address using node .
but can’t figure it out the difference between

  • req.headers[‘x-forwarded-for’]
  • req.connection.remoteAddress
  • req.ip

and one more thing when I console.log(req.headers) i can see

{ host: 'localhost:5000',
connection: 'keep-alive',
'cache-control': 'max-age=0',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883
.87 Safari/537.36',
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'accept-encoding': 'gzip, deflate, sdch, br',
'accept-language': 'en-US,en;q=0.8,de;q=0.6',
'if-none-match': 'W/"4e-vF36fJ92NvD6Kr6FDiktUw"' }

there is no 'x-forwarded-for then how req.headers['x-forwarded-for'] works?