If you’re using Express, `req.hostname` is the way to go for nodejs request source hostname.
It handles the `host` header and ignores port numbers, which is nice.
But if you’re behind a proxy, set `trust proxy` in Express:
```javascript
app.set('trust proxy', true);
```
Then `req.hostname` will respect `x-forwarded-host`.
It handles the `host` header and ignores port numbers, which is nice.
But if you’re behind a proxy, set `trust proxy` in Express:
```javascript
app.set('trust proxy', true);
```
Then `req.hostname` will respect `x-forwarded-host`.
