Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

next-request-ip

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-request-ip

A Next.js-friendly fork of request-ip, optimized for Headers to retrieve client IP addresses.

latest
Source
npmnpm
Version
1.0.7
Version published
Maintainers
1
Created
Source

next-request-ip

CI Coverage Status npm version

A Next.js-friendly fork of request-ip, optimized for working with the Web API Headers to retrieve client IP addresses.

Installation

npm install next-request-ip
# or
yarn add next-request-ip

Usage

App Router (Next.js 13+)

import { getClientIp } from "next-request-ip";
import { headers } from "next/headers";

export default async function Page() {
  const headersList = await headers();
  const clientIp = getClientIp(headersList);

  return (
    <div>
      <p>Your IP: {clientIp}</p>
    </div>
  );
}

API Routes

import { NextResponse, type NextRequest } from "next/server";
import { getClientIp } from "next-request-ip";

export async function GET(request: NextRequest) {
  const ip = getClientIp(request.headers);
  return NextResponse.json({ ip });
}

CommonJS (Node)

// If your environment uses CommonJS you can require the package:
const { getClientIp } = require('next-request-ip');

// Example usage with a standard Fetch-like Request
// (Pass a Headers-compatible object to getClientIp)
const headers = new Headers({ 'x-client-ip': '192.0.2.1' });
console.log(getClientIp(headers)); // '192.0.2.1'

API

getClientIp(headers: Headers): string | null

Returns the client IP address from the request headers, or null if not found.

Checks the following headers in order of priority: Checks the following headers in order of priority (proxy/load-balancer headers first):

  • x-forwarded-for
  • x-original-forwarded-for
  • forwarded
  • forwarded-for
  • x-real-ip
  • x-client-ip
  • x-envoy-external-address (Envoy)
  • x-envoy-client-address (Envoy)
  • x-forwarded
  • x-cluster-client-ip
  • cf-connecting-ip
  • do-connecting-ip
  • fastly-client-ip
  • true-client-ip
  • x-appengine-user-ip
  • Cf-Pseudo-IPv4
  • x-forwarded-for
  • x-original-forwarded-for
  • forwarded
  • forwarded-for
  • x-real-ip
  • x-client-ip
  • x-envoy-external-address (Envoy)
  • x-envoy-client-address (Envoy)
  • x-forwarded
  • x-cluster-client-ip
  • cf-connecting-ip
  • do-connecting-ip
  • x-appengine-user-ip
  • fastly-client-ip
  • true-client-ip
  • Cf-Pseudo-IPv4

Supports both IPv4 and IPv6 addresses.

Differences from request-ip

  • Designed specifically for Next.js and the Web API Headers object
  • No dependencies on Node.js-specific request objects
  • Optimized for modern web standards

Compatibility

  • Minimum Node.js version: >= 20 (see package.json engines)

License

MIT License - see LICENSE file for details.

Credits

This library is a fork of request-ip by Petar Bojinov.

Original copyright notice:

Copyright (c) 2014 Petar Bojinov

Keywords

next

FAQs

Package last updated on 31 Jan 2026

Did you know?

Socket

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.

Install

Related posts