Auto updating maxmind GeoIP lookup for free and paid maxmind accounts with optional cloudflare fallback. Leveringing the excellent node-maxmind package, maxminded manages regular data updates and provides an ultrafast geoip lookup fallback via geos-major and CloudFlare headers when there is a maxmind IP lookup miss.
npm install maxminded
maxmind = ;maxmind; // local init data & free Wednesday updateslocation = maxmind; // City/Location lookup
Start with local free data, until initial paid data is loaded and then do paid data updates every Wednesday.
maxminded = ;maxminded;geo = maxminded;
Use paid data and initialize doing updates every Wednesday and fallback to CloudFlare data until initial download and initialize completes or when maxmind.getLocation() fails to match an ip.
This requires CloudFlare to be enabled for your domain so the cf-country header will be populated.
maxminded = ;maxminded;geo = maxmind; // pass in request headers for fallback
In this example, getLocation() will return
undefined until the initial data is loaded and there is no cf-country header
A bonus of using maxminded is that your geo data doesn't need to be pushed to your PaaS with your code deploy. The geo ip data can be pulled directly from maxmind in compressed form when your application launches.