How to Get the Request Source Hostname in Node.js? or Node.js Request Source Hostname: How to Retriev

18 Replies, 1666 Views

If you're dealing with proxies, the `x-forwarded-for` header is your friend for the nodejs request source hostname.

But heads up—headers can be manipulated, so don’t trust them blindly.

You might wanna use a library like `proxy-addr` to parse it safely:
```javascript
const proxyAddr = require('proxy-addr');
const ip = proxyAddr(req, trustProxy);
```
Check out the docs here: [proxy-addr npm](https://www.npmjs.com/package/proxy-addr).

Messages In This Thread



Users browsing this thread: 1 Guest(s)