A tiny Node.js module to retrieve a request's IP address.
Maintainer: Petar Bojinov
npm install request-ip
var requestIp = require('request-ip');
// inside middleware handler
var ipMiddleware = function(req, res, next) {
var clientIp = requestIp.getClientIp(req); // on loaclhost > 127.0.0.1
next();
};
request-ip looks for three specific headers in the request and falls back some defaults if they do not exist
The following is the order we use to determine the user ip from the request.
X-Client-IP
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.X-Real-IP
X-Cluster-Client-IP
- Permuations of #2 such as:
X-Forwarded
,Forwarded-For
andForwarded
req.connection.remoteAddress
req.socket.remoteAddress
req.connection.socket.remoteAddress
Getting a user's IP for geolocation.
None
Make sure you have the necessary dependencies:
npm install
Run the integration tests
npm test
1.1.0
- add support for X-Cluster-Client-IP, X-Forwarded, Forwarded-For, Forwarded
- add tests
1.0.0
- add semver
0.0.4
- add support for X-Real-Ip
- bug fixes
0.0.3
- improve docs
0.0.2
- bug fix
0.0.1
- initial release
The MIT License (MIT)