Under what conditions can req.connection.remoteAddress be empty (ExpressJS)
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 to share
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 to share