request-public-ip
v1.2.0
Published
Node.js module for retrieving a request's public IP address
Downloads
19
Maintainers
Readme
request-public-ip
request-public-ip is a Node.js module that enables you to retrieve the public IP address of a client's request in Node.js environments. It is particularly useful when you need to identify the public IP address of clients making requests to your server, especially in scenarios where your application is behind a load balancer or proxy.
Installation
You can install the request-public-ip module using npm:
npm install request-public-ip
Usage
To use request-public-ip, follow these steps:
- Import the required functions from the module:
import { getClientPublicIpFromHeaders } from "request-public-ip";
- Pass the request headers to the getClientPublicIpFromHeaders function:
app.use((req, res, next) => {
console.log("Public IP Address:", getClientPublicIpFromHeaders(req.headers));
next();
});
Supported Headers
request-public-ip supports some standard headers used by various platforms and proxies to store client IP information. The following headers are checked to find the public IP address:
- x-client-ip: Used by Amazon EC2, Heroku, and others.
- x-forwarded-for: Used by Load-balancers (AWS ELB) or proxies.
- true-client-ip: Used by Akamai and Cloudflare.
- x-real-ip: Used by nginx proxy/fcgi as an alternative to x-forwarded-for.