request.ip

The remote client IP address of the request.

Since Fastify 5 Spec ↗

Syntax

request.ip

Returns

string — The client IP, honoring trustProxy when enabled.

Examples

import Fastify from 'fastify';

const app = Fastify({ trustProxy: true });

app.get('/ip', async (req) => {
  return { ip: req.ip, forwardedFor: req.ips };
});

Notes

With `trustProxy` enabled, request.ip reflects the X-Forwarded-For chain and request.ips lists all addresses. Without it, ip is the direct socket address.