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-server

v0.0.5

Published

Simple HTTP GeoIP API server.

Downloads

6

Readme

GeoIPServer

GeoIPServer is a small, simple node.js module that allows simple IP geolocation requests. It also comes with a convenient command line utility for creating a standalone server.

Installation

GeoIPServer requires node.js, npm and the requisite data files.

You can install GeoIPServer for use in your own project:

npm install geoip-server

Or you can install GeoIPServer globally, making it easy to run the standalone server:

sudo npm install geoip-server -g

Usage

In your project:

If you're already using express, you can attach GeoIPServer directly to your app:

var GeoIPServer = require( 'geoip-server' );

var geoIPServer = new GeoIPServer( {
    url: '/ip/:ip',
    secret: 'this is the secret key'
} );

geoIPServer.attach( app ); // attach to an existing express app

If you don't already have an express app, you can tell GeoIPServer to listen on its own:

geoIPServer.listen( {
    port: 8888 
} );

GeoIPServer also supports SSL:

geoIPServer.listen( {
    port: 8888,
    ssl: {
        key: './path/to/ssl.key',
        cert: './path/to/ssl.crt',
        port: 4443
    }
} );

As a standalone server:

  Usage: geoip-server [options]

  Options:

    -h, --help                 output usage information
    -s, --secret <secret key>  Specify the secret key for the storehouse. !!REQUIRED!!
    --url <url>                Specify the upload url. Eg: --url "/uploadfile"  Default: /upload
    -p, --port <port>          Specify the port to listen on. Default: 8888
    --sslkey <keyfile>         Specify an SSL key file.
    --sslcert <certfile>       Specify an SSL cert file.
    --quiet                    Do not print out events.

Example:

geoip-server -s "this is the secret key" --url /test/:ip --quiet

This would start a GeoIPServer with the secret key "this is the secret key" that:

  • Has an lookup endpoint url of: /test/:ip
  • Will not print out request logs

Cool, how do I keep everyone on the internet from querying my server?

That's where the secret key comes in: to make a request you must send a signature along for validation.

The signature is a SHA1 of some information about the request plus the secret key.

The signature you send match this signature. To generate a signature, you would execute:

var verification = '';
for ( var key in Object.keys( optionalQueryParams ).sort() ) {
    verification += key + '=' + optionalQueryParams[ key ] + '&';
}

verification += 'ip=' + ipToLookup + '&';
verification += 'secret=' + 'your secret code';

var signature = crypto.createHash( 'sha1' ).update( verification ).digest( 'hex' );

That's great, but how do I generate a signature without leaking my secret key?

Good question! GeoIPServer is mostly intended to be used as a part of an existing web infrastructure where you already have some kind of web service running.

If you're using GeoIPServer internally, you could skip the secret key altogether and just limit incoming connections to approved IPs.

If you'd like to expose it externally, though, you can calculate the signature for the client on your server:

ajaxCall( {
    url: '/api/getipgeolocationsignature',
    type: 'POST',
    data: {
        ip: ipAddressToLookup
    },
    success: function( signature ) {
        // here your API has given us back a signature that allows this request

        ajaxCall( {
            url: '/ip/' + ipAddressToLookup,
            type: 'GET',
            data: {
                signature: signature
            },
            success: function( lookup ) {
                console.log( lookup );
            }
        } );
    }
} );

CREDIT WHERE CREDIT IS DUE

Thanks to Philip Tellis (@bluesmoon) for his geoip-lite library, which GeoIPServer is mostly a small wrapper around.

CHANGELOG

v0.0.1

  • Initial release.