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 🙏

© 2026 – Pkg Stats / Ryan Hefner

sxgeo-node

v0.1.0

Published

Node.js reader for Sypex Geo binary databases.

Downloads

140

Readme

sxgeo-node

sxgeo-node is a Node.js reader for Sypex Geo binary databases.

It works with the official SxGeo.dat and SxGeoCity.dat files and lets you resolve an IPv4 address to:

  • country ISO code
  • country numeric id
  • city data
  • region data
  • full country metadata
  • database metadata

Installation

npm install sxgeo-node

Download a Database

This package does not bundle a database file.

Download one from the official Sypex Geo website and place it somewhere in your project:

  • country database: SxGeo.dat
  • city database: SxGeoCity.dat

Example:

your-project/
  data/
    SxGeoCity.dat
  index.js

Quick Start

CommonJS

const path = require('node:path');
const SxGeo = require('sxgeo-node');

const dbPath = path.join(__dirname, 'data', 'SxGeoCity.dat');
const sxgeo = new SxGeo(dbPath, SxGeo.MEMORY | SxGeo.BATCH);

console.log(sxgeo.getCityFull('1.1.1.1'));

Native ESM

import path from 'node:path';
import { fileURLToPath } from 'node:url';
import SxGeo from 'sxgeo-node';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const dbPath = path.join(__dirname, 'data', 'SxGeoCity.dat');
const sxgeo = new SxGeo(dbPath, SxGeo.MEMORY | SxGeo.BATCH);

console.log(sxgeo.getCityFull('1.1.1.1'));

Example output:

{
  "city": {
    "id": 2174003,
    "lat": -27.46794,
    "lon": 153.02809,
    "name_ru": "Брисбен",
    "name_en": "Brisbane"
  },
  "region": {
    "id": 2152274,
    "name_ru": "Квинсленд",
    "name_en": "State of Queensland",
    "iso": "AU-QLD"
  },
  "country": {
    "id": 16,
    "iso": "AU",
    "lat": -25,
    "lon": 135,
    "name_ru": "Австралия",
    "name_en": "Australia"
  }
}

Constructor

const sxgeo = new SxGeo(databasePath, mode);

Arguments:

  • databasePath: absolute or relative path to SxGeo.dat or SxGeoCity.dat
  • mode: optional bitmask of read modes

Available mode flags:

  • SxGeo.FILE: read from the file on demand
  • SxGeo.MEMORY: preload the data section into memory
  • SxGeo.BATCH: preload indexes for faster repeated lookups

Recommended mode for high-throughput usage:

const sxgeo = new SxGeo(dbPath, SxGeo.MEMORY | SxGeo.BATCH);

Recommended mode for low-memory usage:

const sxgeo = new SxGeo(dbPath, SxGeo.FILE);

API

get(ip)

Returns:

  • getCity(ip) output when the city database is used
  • getCountry(ip) output when the country database is used

getCountry(ip)

Returns a two-letter ISO country code.

sxgeo.getCountry('8.8.8.8');
// "US"

getCountryId(ip)

Returns the numeric country id from the Sypex Geo database.

sxgeo.getCountryId('8.8.8.8');
// 225

getCity(ip)

Returns a short city result:

{
  "city": {
    "id": 2174003,
    "lat": -27.46794,
    "lon": 153.02809,
    "name_ru": "Брисбен",
    "name_en": "Brisbane"
  },
  "country": {
    "id": 16,
    "iso": "AU"
  }
}

getCityFull(ip)

Returns city, region, and full country data.

Use this method when you need country coordinates, localized names, or region details.

about()

Returns metadata about the opened database:

console.log(sxgeo.about());

Example output:

{
  "created": "2026.01.19",
  "timestamp": 1768861974,
  "charset": "utf-8",
  "type": "SxGeo City EN",
  "byteIndex": 224,
  "mainIndex": 1775,
  "blocksInIndexItem": 3376,
  "ipBlocks": 5995209,
  "blockSize": 6,
  "city": {
    "maxLength": 127,
    "totalSize": 2687625
  },
  "region": {
    "maxLength": 175,
    "totalSize": 109649
  },
  "country": {
    "maxLength": 147,
    "totalSize": 9387
  }
}

Notes

  • Only IPv4 lookups are supported.
  • The package reads the official Sypex Geo binary format directly.
  • SxGeoCity.dat already contains country data, so you can use one file for full city lookups.
  • If you only need country codes, SxGeo.dat is smaller and cheaper to load.

Development

Build:

npm run build

Run tests:

npm test