request-public-ip
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

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:

  1. Import the required functions from the module:
import { getClientPublicIpFromHeaders } from "request-public-ip";
  1. 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.

Package Sidebar

Install

npm i request-public-ip

Weekly Downloads

25

Version

1.2.0

License

ISC

Unpacked Size

64.1 kB

Total Files

26

Last publish

Collaborators

  • watchmen-catho