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

geosearch

v0.3.0

Published

Geo location service using multiple free independent services and modules

Downloads

39

Readme

Geosearch is a library covering multiple free geoservices and modules

Including:

  • Maxmind (v1) maxmind-dat
  • Maxmind (v2) maxmind-mmdb
  • Ipgeobase ipgeobase has city, regions and coordinates for Russia and Ukraine only
  • Ip-api.com ip-api
  • Ipinfo.io ipinfo
  • Freegeoip.net freegeoip
  • Geobytes.com geobytes

This module is useful when you need to detect location by ip address with high accuracy. If you have ip addresses mainly from Russia and Ukraine - good options is to set Ipgeobase as first priority.

Installation

npm i geosearch

Usage

 var geo = require("geosearch");
 geo.lookup('8.8.8.8', function (err, result) {
     console.log(err,result);
  });

result is an object containing these geo-properties:

  • city
  • countryCode
  • countryName
  • latitude
  • longitude
  • isp
  • zip
  • regionName
  • regionCode

And also some technical properties:

  • method (last used method)
  • usedMethods (methods used to find requested data and search time fot each of them)
  • requestTime (whole search time, ms)

Answer example:

Answer example

Configuration

GeoSearch has flexible configuration options.

By default only countryCode property is required. To set city as required field:

var options = {};
options.fields = {};
options.fields.city = true;
geo.setOptions(options);

If first completed method's result does not contain all required fields,the resulting object will accumulate all found fields from methods until all required data will have been gathered.

Also you can manage services. This example disables ip-api service and set ipinfo priority level to 10(less level value - higher priority)

options.services = {};
options.services['ip-api'] = false;
options.services['ipinfo'] = 10;

Methods with local geo-databases are the fastest, so they have better priority by default. Also keep in mind that some online services have limitations for amount of requests ion a period of time. ipinfo has daily limit - 1000 requests; geobytes - 16000 requests per hour; So it may not be the best option to set ipinfo top priority if you have thousands of daily ip look-ups

You can tell GeoSearch to double check found result by one field:

options.common = {};
options.common.checkField = 'countryCode';
options.common.checkLevel = 2;

options.common.checkLevel contains number of services which should return equal value of options.common.checkField. In this example callback with result will be executed only after at least two methods return same countryCode.

Methods maxmind-dat, maxmind-mmdb and ipgeobase use local files to get information by ip. Other methods use online services.

To specify path to these files you have to use the following code

options.files = {};
options.files['maxmind-mmdb'] = '/path/to/db/file.mmdb';
options.files['maxmind-dat']['directory'] = '/path/to/directory/containing/dat-files/';

Files for ipgeobase are already in package. If you want to use your own files(maybe newer):

options.files['ipgeobase']['cidrdb'] = '/path/to/countries-db-file/cidr.txt';
options.files['ipgeobase']['citiesdb'] = '/path/to/cities-db-file/citiesdb.txt';

To reset options:

geo.resetOptions();

Reset can be useful if you want to run several geo.lookup with different options.

Run Tests

Tests are written in mocha and chai

$ npm test

Other realizations

PHP version