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

ac-geoip

v3.0.5

Published

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

Downloads

7

Readme

AC GEOIP

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

GEOIP web service requires an account at Maxmind.

You can also use the Geolite2 database from Maxmind: https://dev.maxmind.com/geoip/geoip2/geolite2/

Node.js CI

Usage

Using Webservice

const acgeoip = require('./index')

let geoip = {
  userId: 123456778,
  licenseKey: 'abc-licensekey'
}
acgeoip.init(geoip)

// ASYNC/AWAIT
async() {
  let response = await acgeoip.lookup({ ip: '1.2.3.4' })
}

Using local (Geolite) database

const acgeoip = require('./index')

let geoip = {
  geolite: { 
    enabled: true,
    path: '/path/to/GeoLite2-City.mmdb'
  }
}
acgeoip.init(geoip)

// ASYNC/AWAIT
async() {
  let response = await acgeoip.lookupLocal({ ip: '1.2.3.4' })
}

Combined usage

const acgeoip = require('./index')

let geoip = {
  userId: 123456778,
  licenseKey: 'abc-licensekey',
  geolite: {
    enabled: true,
    path: '/path/to/GeoLite2-City.mmdb'
  }
}
acgeoip.init(geoip)

// lookup using web service
async() {
  let response = await acgeoip.lookup({ ip: '1.2.3.4' })
}

// lookup using local database
async() {
  let response = await acgeoip.lookupLocal({ ip: '1.2.3.4' })
}

Using callbacks

We recommend using modern async/await approach, but you can also use classic callbacks.

// TRADITONAL CALLBACK is available for lookup and lookupLocal 
acgeoip.lookup({
  ip: '8.8.8.8'
}, (err, response) => {
  console.log(response)
})

Init Parameters

Required
Initiate the function with the required "userId" and "licenseKey" if you want to use the webservice. If you want to use local database, make sure to set geolite.enabled to true and provide the location of the database.

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' },
      // the following properties are only available using the paid webservice
      { 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 AG, Mark Poepping