Best node.js module for finding location? [closed]
Asked Answered
T

3

59

I had found couple of node.js modules for finding the information about client location and network using ip address.

Requirements:

  1. Location - country, city, state, latitude, longitude etc.

  2. Network - Internet service Provider, Internet connection type and internet speed etc.

  3. Data Accuracy - maximum possibility.

Note: Looking for server side solution.

The above mentioned modules uses maxmind data. And i had read about the maxmind data accuracy as well.

I am little confused to choose the above node.js modules and i like to know is there any better node.js frameworks available for finding information which met my requirement or any other language plugins which can be portable to node.js.

Any idea will be greatful.

Transform answered 21/5, 2013 at 7:40 Comment(4)
@josliber this question is important and doesn't concern opinion. it concerns the most effective latency method for ip to location conversion.Mandie
@Mandie Questions that ask for recommendations are off topic on stack overflow, which is why I closed the question. You can read more about what is on topic on this site at stackoverflow.com/help/on-topic.Zebapda
IPLocate.io provides a free API: https://www.iplocate.io/api/lookup/8.8.8.8. Docs and usage, including from Node.js, on the home page: www.iplocate.io - Disclaimer: I run this service.Defection
I think this nodejs module might be for you locationLatoyialatreece
D
55

Using IP-based geolocation is possible, but not very accurate. So I suggest you to think about going with a hybrid approach, like trying to get the users location via the HTML5 geolocation API inside the browser and fallback to the serverside if necessary.

I took a look at the two most used geoip/-location modules available for node.js and they both use the datasets provided by MaxMind. AFAIK you have to keep these databases up-2-date manually, which is a clear downer. So you may consider writing a little sync service / script, which updates the database once per month. (More information on MaxMinds free solution can be found here).

kuno/GeoIP is a GeoIP binding, so at it's core it's using the libGeoIP C library, which is okay, but maybe not as portable as the pure JavaScript implementation bluesmoon/node-geoip offers. Both are okay and it's up to you which library you like more. In terms of performance you have to do some benchmakrs (if this topic matters to you) … There is no general answer to the question, which type of module (C-binding/native) will be faster.

If you're willing to spend a few bucks you could also look into MaxMinds Web Service, which is a simple REST API and will be the most precise way to go. The documentation is quite good – so getting started with that won't be a problem.

Disavowal answered 23/5, 2013 at 13:32 Comment(4)
first of all thanks for the valuable info, I have implemented and tested kuno/GeoIP , its not giving these informations Internet service Provider, Internet connection type becoz there is no free database for this one otherwise kuno/geoip is good.Transform
@Disavowal what do you mean by AFAIK?Mandie
@Mandie AFAIK - As Far As I Know lolTransform
Not very accurate is an understatement. Apple, for instance, typically only finds me within 962 km (598 miles) of my current location. And that's still a little too close.Euroclydon
E
29

If you get the IP, you can always call an external service to get the location information such as freegeoip.net and using the request module.

(ip, location) ->
  url = 'http://freegeoip.net/json/' + ip
  request.get url, (error, response, body) ->
    if !error && response.statusCode == 200
      data = JSON.parse body
      location data

For the network infos, I don't have a solution, but I'm looking for one too.

Engulf answered 29/5, 2013 at 17:46 Comment(8)
I agree, if OP is looking for accuracy, I would use an external service like google's map library. Using HTML5 will only get the location if the user allows it.Martinmartina
Do you know how to get the Client's IP ? Tell me, if you don't, I'll edit my answer.Engulf
yes var ip = request.headers['x-forwarded-for'] || request.connection.remoteAddress;Transform
x-forwarded-for is a header only valid if you are behind a proxy if I am correct.Prevaricator
No, not especially. It's the most common way to get the IP address or spoof it.Engulf
This has now become a paid service.Lavatory
Not really. It's now named ipstack and still free for 10k requests per month.Engulf
It's now currently only 100 free requests a month.Hypethral
D
13

You can get all of the information you're after from my API at http://ipinfo.io API:

$ curl ipinfo.io
{
  "ip": "67.188.232.131",
  "hostname": "c-67-188-232-131.hsd1.ca.comcast.net",
  "city": "Mountain View",
  "region": "California",
  "country": "US",
  "loc": "37.4192,-122.0574",
  "org": "AS7922 Comcast Cable Communications, Inc.",
  "postal": "94043"
}

It supports JSONP and CORS, so you can use it either server or client side. More details are available at http://ipinfo.io/developers

Deflagrate answered 5/7, 2014 at 16:44 Comment(4)
I created this module, maybe you can integrate it into your answer: github.com/IonicaBizau/node-ipinfo :-)Pacificas
ipinfo.io works nicely, but beware, if you want to use it over https you have to pay.Babb
ipinfo.io/json/<ipaddress> works perfectlySulla
@Babb not anymore apparently free users get https nowAubine

© 2022 - 2024 — McMap. All rights reserved.