Julio Seña Julio Seña - 1 year ago 157
Node.js Question

how get ip client using express 4.x

I want to get the client's IP and I 'm trying with localhost

( )
but I always get
:: 1

i 'm trying using

app.enable('trust proxy');
app.set('trust proxy', 'loopback');

res.send(req.ip); //I always get :: 1
// or
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
res.send(ip);//I always get :: 1

how can get
and not
:: 1
. this can be done?

Answer Source

::1 is the IPv6 equivalent of localhost. If you want to only have your server listen over IPv4 and thus only have IPv4 addresses come in from your clients, you can specify an IPv4 address in app.listen():

app.listen(3000, '');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download