title: Get only IPv4 ips via NodeJS express
body: <p>I have a <code>NodeJS</code> <code>express</code> service running on <code>Centos</code> and listens to GET requests and I need to identify the IP of the user.</p>
  
  <p>Currently, I'm using this script</p>
  
  <pre><code>ip = req.headers['x-forwarded-for'] ||
        req.connection.remoteAddress ||
        req.socket.remoteAddress ||
        req.connection.socket.remoteAddress
  </code></pre>
  
  <p>The problem is that sometimes the IP returned is IPv4 and sometimes it is IPv6. Is there a way to get only IPv4 IPs?</p>