ac-geoip
Lookup IP addresses at Maxmind GEOIP services and prepare the response with custom field mapping. OPtionally, you can store the response in Redis to improve performance (of your app).
Last updated 8 months ago by mmpro .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ac-geoip 
SYNC missed versions from official npm registry.

AC GEOIP

Lookup IP addresses at Maxmind GEOIP services and prepare the response with custom field mapping. OPtionally, you can store the response in Redis to improve performance (of your app).

GEOIP service requires an account at Maxmind.

Usage

const acgeoip = require('./index')

let geoip = {
  userId: 123456778,
  licenseKey: 'abc-licensekey'
}

acgeoip.init(geoip)

acgeoip.lookup({
  ip: '8.8.8.8'
}, (err, result) => {
  console.log(result)
})

Init Parameters

Required
Initiate the function with the required "userId" and "licenseKey".

Mapping
Define how your response looks like using a mapping array. The array contains objects with properties "response" which is the property name in the response and "geoIP" which is the path to the GeoIP response.

See this default setup as example

 mapping: [
      { response: 'iso2', geoIP: 'country.iso_code' },
      { response: 'city', geoIP: 'city.names.en' },
      { response: 'region', geoIP: 'subdivisions[0].names.en' },
      { response: 'isp', geoIP: 'traits.isp' },
      { response: 'organization', geoIP: 'traits.organization' },
      { response: 'domain', geoIP: 'traits.domain' },
      { response: 'location', geoIP: 'location' },
    ]

Caching
In order to cache the data, you need to provide:

  • redis - a redis instance (from ioredis)
  • environment - prefix (default development) for the redisKey (e.g development:geoip:8.8.8.8)
  • cacheTime - seconds to cache the GeoIP response (default 7 days)

Links

Thanks

Thanks to https://github.com/maxmind/GeoIP2-node

License

MIT License Copyright © 2009-present, AdmiralCloud, Mark Poepping

Current Tags

  • 1.0.4                                ...           latest (8 months ago)

5 Versions

  • 1.0.4                                ...           8 months ago
  • 1.0.3                                ...           8 months ago
  • 1.0.2                                ...           8 months ago
  • 1.0.1                                ...           8 months ago
  • 1.0.0                                ...           8 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (9)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |