Under what conditions can req.connection.remoteAddress be empty (ExpressJS)

I have an express application running under Node.js v6.9.4, running over both HTTP and HTTPS.

I noticed on several occasions that the incoming requests had empty remoteAddress data.

Under what conditions does a request have no / empty remote address?

+3


source to share


2 answers


the remote address is empty if behind a proxy server

https://github.com/hapijs/hapi/issues/1210



you can use

const ip = req.headers['x-forwarded-for'] || (req.connection && req.connection.remoteAddress) || ''

      

+4


source


Express behind proxy servers

Although the application will not work if the trusted proxy for the application is not configured, it will incorrectly register the proxys IP as the client's IP if the trusted proxy is not configured.



An alternative solution for getting the IP address is provided by @ trushar-gupta p>

You can also read more about Express proxies   here

0


source







All Articles