Skip to content

Instantly share code, notes, and snippets.

@VadimChorrny
Created February 19, 2024 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VadimChorrny/082230592d3cb21d97a23767368ce13c to your computer and use it in GitHub Desktop.
Save VadimChorrny/082230592d3cb21d97a23767368ce13c to your computer and use it in GitHub Desktop.
Simple way to get IP-address from request in Express.
async getMyIp(req: Request, res: Response) {
const ip =
req.headers["cf-connecting-ip"] ||
req.headers["x-real-ip"] ||
req.headers["x-forwarded-for"] ||
req.socket.remoteAddress || "";
return res.status(200).send({ip});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment