Node.js: Get client's IP

前端 未结 5 1693
我在风中等你
我在风中等你 2020-12-03 01:13

req.connection.remoteAddress, req.headers[\'x-forwarded-for\'], req.ip, req.ips, what does it all mean?

Is there a straight forward way to simply get the IP address

5条回答
  •  情话喂你
    2020-12-03 01:41

    req.ip is the straightforward way to get the client's IP address in Express. You can see the logic it uses (which involves grabbing the first item from the array of proxy addresses req.ips, where that array is constructed from the x-forwarded-for headers) here.

提交回复
热议问题