24.10.0 • Published 9 months ago

turbo-geoip-country v24.10.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
9 months ago

turbo-geoip-country

This is an updated, performance-focused fork of node-geoip with only country data. Inspired by geoip-ultralight

This product uses GeoLite data created by MaxMind, available from https://www.maxmind.com/

šŸ’” You would need to create an account and get a license key to update data by yourself

Build Status

How to install šŸŽ

npm install turbo-geoip-country --save

How to use it šŸ¤–

const turboGeoip = require('turbo-geoip-country');

const ip = "207.97.227.239";
const country = turboGeoip.getCountry(ip);
console.log(country);
'US'

// Also it works with anonymized ip
const ip = "207.97.227.0";
const country = turboGeoip.getCountry(ip);
console.log(country);
'US'

Why turbo-geoip-country āš”ļø

  • šŸš€ Get country code (2 letter ISO-3166-1) by IP v4/v6
  • šŸ”’ Works also with anonymized IP
  • šŸ”„ Performance focused (see the section below)
  • āœ… Less than 19 MB memory footprint (instead of +110 MB of node-geoip)
  • ā° Data updated on 30th October 2024
  • šŸ“… Using Calendar versioning
  • 🌐 Production-ready, used by Ghostboard.io
  • āš”ļø Dependencies updated and 5 of them removed
  • šŸ¤“ Code reduced

Performance šŸ”„

šŸ’” Based on the average performance of 10 executions of each package on a 2018 Mac Mini i7 6c12t 16GB

Metricnode-geoipturbo-geoip-countrydelta
Startup time47 ms17 ms63.83 % faster
Time to find 1 ip7 μs/ip4 μs/ip42.86 % faster
IP lookups per second139534.884 ip/s250000.000 ip/s44.19 % more ip/s

Test yourself node test/performance.js

Found 30000 (17030/12970) ips in 120ms (250000.000 ip/s) (4μs/ip)
Took 17 ms to startup

vs node-geoip node test/geo-lookup.js

Found 30000 (16917/13083) ips in 215ms (139534.884 ip/s) (7μs/ip)
Took 47 ms to startup

How to update the data šŸ”‘

  • Log in into your MaxMind account
    • šŸ’” You can create a MaxMind account here
  • Go to "GeoIP 2 / GeoLite 2" > Downloads
  • Download the "GeoLite2 Country: CSV Format" zip
  • Unzip and put the files into the input folder
  • Run npm run regenerate
    • šŸ’” This takes about 1 minute or less

Tests āœ…

Run npm t

> nodeunit test/tests.js


tests.js
āœ” testLookup
āœ” testDataIP4
āœ” testDataIP6
āœ” testUpdatedIps

OK: 7 assertions (19ms)

References

Copyright

geoip-lite is Copyright 2011-2018 Philip Tellis philip@bluesmoon.info and the latest version of the code is available at https://github.com/bluesmoon/node-geoip

License

There are two licenses for the code and data. See the LICENSE file for details.

24.10.0

9 months ago

24.7.0

1 year ago

24.4.0

1 year ago

24.1.0

2 years ago

23.7.0

2 years ago

23.10.0

2 years ago

23.4.0

2 years ago

23.1.0

3 years ago

22.10.0

3 years ago

22.4.0

3 years ago

22.1.0

3 years ago

1.5.0

4 years ago