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

geoip-ultralight

v0.1.5

Published

Super lightweight GeoIP implementation with country data

Downloads

6,742

Readme

geoip-ultralight

An even lighter alternative to geoip-lite and libGeoIP wrappers. It provides country data for IP addresses based on the GeoLite data from MaxMind. It does not provide city, state or region data. Forked from geoip-lite.

Build Status

Why

Unlike other geoip libraries for node, geoip-lite and geoip-ultralight don't require compiling libGeoIP; they're JavaScript implementations. While neither offer the full functionality of geoip, they're significantly faster.

geoip-lite is fairly light already, boasting 6 microsecond lookups for IPv4 addresses, and 30 microsecond lookups for IPv6 on a Macbook Pro. However, it ships over 60MB of data for handling city/region names, and thus introduces significant memory overhead. If all you want is country data, and not city/regions, then that's a lot of RAM for unused functionality.

Instead, geoip-ultralight includes under 2MB of data, and has negligible memory consumption. If all you need is to identify countries, this will work perfectly with your Digital Ocean or AWS micro instances.

Installation

It can be installed via npm using:

npm install --save geoip-ultralight

Usage

var geoip = require('geoip-ultralight');

// Unlike geoip-lite's lookup() call, geoip-ultralight exposes
// a lookupCountry() function to avoid confusion
var ip = "207.97.227.239";
geoip.lookupCountry(ip); // => "US"

API

geoip-ultralight is completely synchronous. There are no callbacks involved. All blocking file IO is done at startup time, so runtime calls are executed quickly in memory. Startup may take up to 200ms while reading and indexing files into memory.

lookupCountry

The function accepts IP addresses in dotted quad notation, IPv6 colon notation, as well as 32bit unsigned integers (treated as IPv4). Note that any square brackets should be removed from IPv6 addresses beforehand.

var country = geoip.lookupCountry(ip);

If the IP address was found, lookupCountry returns a 2 letter ISO-3166-1 country code. Otherwise it returns null.

pretty

Given a 32bit unsigned integer, pretty will return a human readable string equivalent.

geoip.pretty(ip);

The function returns a string if the format was recognized, otherwise it returns the original input.

startWatchingDataUpdate

When invoked, the server will watch the data directory for changes and reload the in-memory geo data as necessary.

geoip.startWatchingDataUpdate();

This can be used along with npm run-script updatedb to periodically update geo data on a running server.

stopWatchingDataUpdate

Stops the server from watching the data dir for updates.

geoip.stopWatchingDataUpdate();

Built-in Updater

The package contains an update script that can pull geo data from MaxMind and handle the necessary conversions into a compatible format.

npm run-script updatedb