Created
September 27, 2022 22:18
-
-
Save KellynCodes/f4a75b2a28046c0843061ddaccd2c874 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