Need help with request-ip?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

570 Stars 71 Forks MIT License 144 Commits 13 Opened issues


A Node.js module for retrieving a request's IP address on the server.

Services available


Need anything else?

Contributors list


A tiny Node.js module for retrieving a request's IP address.

Coverage Status npm version


npm install request-ip --save

Getting Started

const requestIp = require('request-ip');

// inside middleware handler const ipMiddleware = function(req, res, next) { const clientIp = requestIp.getClientIp(req); next(); };

// on localhost you'll see if you're using IPv4 // or ::1, ::ffff: if you're using IPv6

As Connect Middleware

const requestIp = require('request-ip');

app.use(function(req, res) { const ip = req.clientIp; res.end(ip); });

To see a full working code for the middleware, check out the examples folder.

The connect-middleware also supports retrieving the ip address under a custom attribute name, which also works as a container for any future settings.

How It Works

It looks for specific headers in the request and falls back to some defaults if they do not exist.

The user ip is determined by the following order:

  1. X-Client-IP

  2. X-Forwarded-For
    (Header may return multiple IP addresses in the format: "client IP, proxy 1 IP, proxy 2 IP", so we take the the first one.)
  3. CF-Connecting-IP
  4. Fastly-Client-Ip
    (Fastly CDN and Firebase hosting header when forwared to a cloud function)
  5. True-Client-Ip
    (Akamai and Cloudflare)
  6. X-Real-IP
    (Nginx proxy/FastCGI)
  7. X-Cluster-Client-IP
    (Rackspace LB, Riverbed Stingray)
  8. X-Forwarded
    (Variations of #2)
  9. req.connection.remoteAddress
  10. req.socket.remoteAddress
  11. req.connection.socket.remoteAddress

If an IP address cannot be found, it will return


Samples Use Cases

  • Getting a user's IP for geolocation.

Running the Tests

Make sure you have the necessary dev dependencies needed to run the tests:

npm install

Run the integration tests

npm test

Release Notes

See the wonderful changelog

To easily generate a new changelog, install github-changelog-generator then run

npm run changelog


  • Thanks to @osherx for adding the connect-middleware.
  • Thanks to @raunc for adding Squid proxy support.
  • Thanks to @fluxsauce for adding
    , and ES6 support.
  • Thanks to @vishalvijay for adding Fastly/Firebase hosting support.


The MIT License (MIT) - 2018

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.