Skip to content

Instantly share code, notes, and snippets.

@Shaxadhere
Last active December 15, 2022 08:29
Show Gist options
  • Save Shaxadhere/0e453488e9306057fac2678e47204009 to your computer and use it in GitHub Desktop.
Save Shaxadhere/0e453488e9306057fac2678e47204009 to your computer and use it in GitHub Desktop.
get request information in express js server.
const { UAParser } = require("ua-parser-js")
const ipLocator = require('ip-locator')
const parser = new UAParser(req.headers['user-agent']);
const result = parser.getResult()
const ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress
ipLocator.getDomainOrIPDetails(ip, "json", function (err, ipInfo) {
res.json({ result, ipInfo })
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment