Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding Location through IP address Nodejs mongodb

I'm trying to find the location of an IP address. The IP address will be sent to the API through a front end android/iOS application(I'm currently using a static IP address of my computer). I want to use the client IP address to then determine their, likely, physical location and send the location to MongoDB to be stored. Any help regarding this will be appreciated. Thanks in advance.

like image 583
Nouman Khan Avatar asked Jan 29 '23 13:01

Nouman Khan


1 Answers

You can utilize GeoIP-lite to get the geodata from the ip address.

var geoip = require('geoip-lite');

var ip = "207.97.227.239";
var geo = geoip.lookup(ip);

console.log(geo);
/*{ range: [ 3479297920, 3479301339 ],
  country: 'US',
  region: 'TX',
  city: 'San Antonio',
  ll: [ 29.4889, -98.3987 ],
  metro: 641,
  zip: 78218 }*/
like image 154
Ridham Tarpara Avatar answered Jan 31 '23 08:01

Ridham Tarpara