Last active
September 27, 2022 22:21
-
-
Save KellynCodes/b44ecc0017313be01d9d0eef9fd96393 to your computer and use it in GitHub Desktop.
How to get users IP address on Express Js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = express(); | |
app.get('/',function(req, response) { | |
const ipAddress = req.header('x-forwarded-for') || | |
req.socket.remoteAddress; | |
res.send(ipAddress); | |
}); | |
app.listen(3000, () => console.log(`Server is listening on port 3000`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment