
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
request-ip
Advanced tools
A tiny Node.js module for retrieving a request's IP address.

Yarn
yarn add request-ip
npm
npm install request-ip --save
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 127.0.0.1 if you're using IPv4
// or ::1, ::ffff:127.0.0.1 if you're using IPv6
const requestIp = require('request-ip');
app.use(requestIp.mw())
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.
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:
X-Client-IPX-Forwarded-For (Header may return multiple IP addresses in the format: "client IP, proxy 1 IP, proxy 2 IP", so we take the first one.)CF-Connecting-IP (Cloudflare)Fastly-Client-Ip (Fastly CDN and Firebase hosting header when forwared to a cloud function)True-Client-Ip (Akamai and Cloudflare)X-Real-IP (Nginx proxy/FastCGI)X-Cluster-Client-IP (Rackspace LB, Riverbed Stingray)X-Forwarded, Forwarded-For and Forwarded (Variations of #2)appengine-user-ip (Google App Engine)req.connection.remoteAddressreq.socket.remoteAddressreq.connection.socket.remoteAddressreq.info.remoteAddressCf-Pseudo-IPv4 (Cloudflare fallback)request.raw (Fastify)If an IP address cannot be found, it will return null.
Make sure you have the necessary dev dependencies needed to run the tests:
npm install
Run the integration tests
npm test
Compiles the current ES6 code to ES5 using Babel.
npm build
See the wonderful changelog
To generate a new changelog, install github-changelog-generator then run npm run changelog. This will require being on Ruby >= 3
Thank you to all the contributors!
The MIT License (MIT) - 2022
The 'ip' package provides utilities for IP address manipulation, including functions to validate, convert, and compare IP addresses. While it offers more general IP address utilities, it does not specifically focus on extracting IP addresses from request objects like request-ip.
The 'forwarded' package is used to parse the X-Forwarded-For header to get the client's IP address. It is more specialized in handling forwarded headers but lacks the broader support for different request types and sources that request-ip provides.
The 'express-ip' package is an Express.js middleware for retrieving the client's IP address. It is similar to request-ip but is specifically designed for Express.js applications and may not be as versatile for other types of Node.js applications.
FAQs
A small Node.js module to retrieve the request's IP address
The npm package request-ip receives a total of 2,412,003 weekly downloads. As such, request-ip popularity was classified as popular.
We found that request-ip demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.