Created
January 27, 2021 06:38
-
-
Save tesh254/21495441c7823982b282871c2a7182b9 to your computer and use it in GitHub Desktop.
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 { lookup } = require("geoip-lite"); | |
const app = express(); | |
const router = express.Router(); | |
router.get("/some-ip", (req, res) => { | |
const ip = req.headers["x-forwarded-for"] || req.connection.remoteAddress; | |
const result = lookup(ip); | |
res.status(200).json({ | |
ip, | |
...result, | |
}); | |
}); | |
app.use("/", router); | |
app.listen(5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment