get client ip address in express.js

According to this, do following to determine the client ipaddress:

1
2
3
4
var ip = (req.headers['x-forwarded-for'] ||
req.connection.remoteAddress ||
req.socket.remoteAddress ||
req.connection.socket.remoteAddress).split(",")[0];