npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

turbo-geoip-country

v24.10.0

Published

An updated, performance-focused fork of node-geoip with only country data

Downloads

689

Readme

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

| Metric | node-geoip | turbo-geoip-country | delta | | ------- | ------- | ------- | ------- | | Startup time | 47 ms | 17 ms | 63.83 % faster | | Time to find 1 ip | 7 μs/ip | 4 μs/ip | 42.86 % faster | | IP lookups per second | 139534.884 ip/s | 250000.000 ip/s | 44.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 [email protected] 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.