Express.js req.ips Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Request

Definition

In Express.js, req.ips is a string array of addresses from the X-Forwarded-For header when trust proxy is enabled. If trust proxy is off (the default) or the header is missing, it is [].

Use it behind reverse proxies or load balancers to inspect the hop list. For a single client IP, prefer req.ip. Configure trust with app.set('trust proxy', …).

Syntax

Read req.ips in your Express.js route handler. Start with this line.

Express
req.ips
CallWhat it does
req.ipsPrimary signature.

Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.

Library declarations
Express
const express = require("express");
const app = express();

req.ips

Parameters

ParameterDescription
app.set('trust proxy', …)Required. Tells Express which proxies to trust
X-Forwarded-For headerRequired. Source of the address list
req.ipsOptional. Full forwarded chain as String[]
req.ipOptional. Single selected client IP

Return Value

req.ips is an array of addresses parsed from X-Forwarded-For when trust proxy is enabled. Without trust, it is typically an empty array [].

Express
app.set('trust proxy', 1);
req.ips; // e.g. ['client', 'proxy'] depending on headers
req.ip;  // usually the left-most trusted address

Express.js Examples

Example 1 — Default Empty Array

Without trust proxy, req.ips stays empty even if a client sends X-Forwarded-For.

Express
const express = require('express');
const app = express();

app.get('/chain', (req, res) => {
  res.json({ ips: req.ips });
});

app.listen(3000);

How It Works

  1. Default trust is off. Express treats the app as facing the client directly.
  2. Forwarding headers are ignored. X-Forwarded-For does not fill req.ips.
  3. Empty array is returned. req.ips is always [] in this setup.
  4. Enable trust when behind a proxy. See the next example.

Example 2 — Read the Forwarded Chain

Enable trust, then return the parsed hop list from X-Forwarded-For.

Express
const express = require('express');
const app = express();

// One reverse proxy in front of the app
app.set('trust proxy', 1);

app.get('/chain', (req, res) => {
  res.json({ ips: req.ips });
});

app.listen(3000);

How It Works

  1. Match the hop count. app.set('trust proxy', 1) trusts one proxy layer — safer than blind true when you know the topology.
  2. Proxy adds the header. Addresses arrive as a comma-separated X-Forwarded-For list.
  3. Express builds an array. That list becomes req.ips as strings.
  4. Order stays left-to-right. Client first; furthest downstream proxy last.

Example 3 — Log Client IP and Hop Chain

Log both req.ip and req.ips in middleware for request audits.

Express
const express = require('express');
const app = express();

app.set('trust proxy', 1);

app.use((req, res, next) => {
  console.log('client:', req.ip);
  console.log('chain:', req.ips);
  next();
});

app.get('/', (req, res) => {
  res.send('ok');
});

app.listen(3000);

How It Works

  1. Trust once at startup. Middleware and routes then share the same proxy rules.
  2. Middleware runs first. Every request logs before the route handler.
  3. req.ip is the selected client. Use it for “who called?” summaries.
  4. req.ips is the full chain. Keep it for hop-level debugging, then call next().

Runtime Support

req.ips is an Express.js request property. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers do not execute it — they only send HTTP requests to your app.

✓ Server · Express 4 & 5

req.ips

Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers. Not available in the browser.

Server Node.js runtime API
Node.js 18+ for Express 5 · 14+ typical for Express 4
Supported
Bun Express-compatible server apps
Supported
Deno Via npm compatibility / adapters
Supported
req.ips Express on Node.js

Bottom line: Study and run these examples with Node.js and the express package. Copy a snippet into a local file and start the server with node.

Frequently Asked Questions

It is a string array of IP addresses from the X-Forwarded-For header when trust proxy is enabled. Otherwise it is an empty array.
trust proxy defaults to false. Without enabling it (or without an X-Forwarded-For header), Express leaves req.ips empty.
req.ip is one selected client IP. req.ips is the full forwarded chain from X-Forwarded-For when proxies are trusted.
For X-Forwarded-For: client, proxy1, proxy2, Express reports ["client", "proxy1", "proxy2"], where proxy2 is the furthest downstream hop.
No. It is a server-side request property. Browsers only send HTTP requests; your Express app reads req.ips on the server.

Next: req.is()

Check the request Content-Type with a simple MIME-type helper.

req.is() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful