Skip to content

Instantly share code, notes, and snippets.

@tesh254
Created January 27, 2021 06:38
Show Gist options
  • Save tesh254/21495441c7823982b282871c2a7182b9 to your computer and use it in GitHub Desktop.
Save tesh254/21495441c7823982b282871c2a7182b9 to your computer and use it in GitHub Desktop.
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