closest-region

node-whichregion ================

npm install closest-region

Dependencies

  • libgeoip
brew install libgeoip

JS Example

closestRegion = require("closest-region")();

var ip = "xxx.xxx.xx.xx";

closestRegion(ip, function(err, regionName) {

});

Express Example


var express = require("express"),
closestRegion = require("closest-region")();

var server = express();

server.get("/ec2/region", function(req, res) {
  closestRegion(req, function(err, region) {
    res.end(region);
  });
});

Custom Geo data

closestRegion = require("closest-region")({
  cityDataPath: "/path/to/city/data"
});

var ip = "xxx.xxx.xx.xx";

closestRegion(ip, function(err, regionName) {

});

With node-ectwo

```javascript

closestRegion(ip, function(err, regionName) { ectwo.regions.findOne({ name: regionName || "us-east-1" }, function(err, region) { //do stuff with the target region }); });

npm loves you