Less memory usage version of geoip-lite by supporting only country lookup.
Installations
npm install geoip-country
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=10.20.0
Node Version
20.18.2
NPM Version
10.8.2
Score
96.3
Supply Chain
99.6
Quality
94.5
Maintenance
100
Vulnerability
85.1
License
Releases
v5.0.0 Less memory usage and Faster startup and Faster lookup
Published on 26 Aug 2024
v4.0.0 New MaxMind GeoLite2 License version
Published on 23 Jan 2020
v3.4.0
Published on 31 Dec 2019
v3.3.0
Published on 16 Nov 2019
v3.2.5
Published on 05 Sept 2019
v3.2.2
Published on 20 Jun 2019
Contributors
Unable to fetch Contributors
Languages
JavaScript (98.67%)
Shell (1.33%)
Developer
sapics
Download Statistics
Total Downloads
10,929,052
Last Day
21,140
Last Week
111,549
Last Month
450,213
Last Year
5,313,366
GitHub Statistics
89 Stars
651 Commits
13 Forks
6 Watching
6 Branches
1 Contributors
Bundle Size
49.12 kB
Minified
16.59 kB
Minified + Gzipped
Package Meta Information
Latest Version
5.0.202501312341
Package Id
geoip-country@5.0.202501312341
Unpacked Size
7.28 MB
Size
3.14 MB
File Count
12
NPM Version
10.8.2
Node Version
20.18.2
Publised On
31 Jan 2025
Total Downloads
Cumulative downloads
Total Downloads
10,929,052
Last day
42.4%
21,140
Compared to previous day
Last week
-9.9%
111,549
Compared to previous week
Last month
36.2%
450,213
Compared to previous month
Last year
85.3%
5,313,366
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
4
Dev Dependencies
3
[!CAUTION] This repository would not maintaine any more. We recommend to use new library ip-location-api which has faster and customizable system, we created from scratch.
geoip-country
A native nodejs API to get country information from ip address.
This library is fork of the geoip-lite which provides a very fast ip to geolocation API by loading the ip to geolocation database into memory. However, because the database contains city and coordinate information, etc., its size exceeds 120 MB, which means that it uses a lot of memory and takes a long time before the first execution.
geoip-country
reduces memory usage and faster startup and faster lookup by restricting database to country from geolocation.
Futhermore, we add the other information capital
, continent_name
, languages
, etc., from v5.
You can check the test/benchmark.js
after updating geoip-lite
database.
The following tests were performed on Node.js v20 on a PC using SSD.
benchmark | database size | startup time | lookup time |
---|---|---|---|
geoip-country | 7 MB | 17 ms | 0.95 μs/ip |
geoip-lite | 124MB | 52 ms | 2.37 μs/ip |
This product includes GeoLite2 ipv4 and ipv6 country data created by MaxMind. The database of this product updates twice a weekly.
You should read this README and the LICENSE and EULA files carefully before deciding to use this product.
After v4, LICENSE for the GeoLite2 database was changed. If you need to use this product with previous LICENSE, please use v3.
Synopsis
1var geoip = require('geoip-country'); 2 3var ip = "207.97.227.239"; 4var geo = geoip.lookup(ip); 5 6console.log(geo); 7{ 8 country: 'US', // "2 letter" country code defined at ISO-3166-1 alpha-2 9 name: 'United States', 10 native: 'United States', 11 continent: 'NA', 12 continent_name: 'North America', 13 phone: [ 1 ], 14 capital: 'Washington D.C.', 15 currency: [ 'USD', 'USN', 'USS' ], 16 languages: [ 'en' ], 17}
Installation
1$ npm i geoip-country
API
geoip-country is completely synchronous. There are no callbacks involved. All blocking file IO is done at startup time, so all runtime calls are executed in-memory and are fast. Startup may take up to 20ms while it reads into memory and indexes data files.
Looking up an IP address
If you have an IP address in dotted quad notation, IPv6 colon notation, or a 32 bit unsigned integer (treated
as an IPv4 address), pass it to the lookup
method.
1var geo = geoip.lookup(ip);
If the IP address was found, the lookup
method returns an object with the following structure:
1{ 2 country: 'CN', // "2 letter" country code defined at ISO-3166-1 alpha-2 3 name: 'China', 4 native: 'ä¸å›½', 5 continent: 'AS', 6 continent_name: 'Asia', 7 phone: [ 86 ], 8 capital: 'Beijing', 9 currency: [ 'CNY' ], 10 languages: [ 'zh' ], 11}
If the IP address was not found, the lookup
returns null
.
We use two databases for getting ip address
to geo
data.
First is GeoLite2 country
database for linking ip address
to country
which is "2 letter" country code which is defined at ISO-3166-1 alpha-2 wiki.
Second database is Countries database which is published under MIT License for linking country
to languages
, capital
, continent
, etc.
Built-in Updater
This package contains an update script that can pull the files from MaxMind and handle the conversion from CSV. A npm script alias has been setup to make this process easy. Please keep in mind this requires internet and MaxMind rate limits that amount of downloads on their servers.
1npm run updatedb --license_key=YOUR_GEOLITE2_LICENSE_KEY 2 or 3GEOLITE2_LICENSE_KEY=YOUR_GEOLITE2_LICENSE_KEY node scripts/updatedb.js
YOUR_GEOLITE2_LICENSE_KEY should be replaced by a valid GeoLite2 license key. Please follow instructions provided by MaxMind to obtain a license key.
Update database API [Added at v4.1.0]
You can update country database with updateDatabase
method.
1 geoip.updateDatabase(license_key, callback);
license_key
is a license key which provided by MaxMind.
You can get GeoLite2 license key as instructions.
By setting the environmental variable GEOLITE2_LICENSE_KEY
, you can update with
1 geoip.updateDatabase(callback);
Fast lookup setting
By setting CLI parameter --geoip_fast_lookup=XX
or envirnment GEOIP_FAST_LOOKUP=XX
, you can make faster lookup time, in exchange for slower startup time and increase memory usage.
Default of geoip_fast_lookup
is 12, 4 is minimum and 18 is maximum.
geoip_fast_lookup | increased memory usage | startup time | lookup time |
---|---|---|---|
4 [min] | 192 B | 13 ms | 1.15 μs/ip |
6 | 768 B | 13 ms | 1.11 μs/ip |
8 | 3 KB | 13 ms | 1.07 μs/ip |
10 | 12 KB | 15 ms | 1.00 μs/ip |
12 [default] | 48 KB | 17 ms | 0.95 μs/ip |
14 | 192 KB | 19 ms | 0.91 μs/ip |
16 | 768 KB | 22 ms | 0.87 μs/ip |
18 [max] | 3 MB | 31 ms | 0.84 μs/ip |
20 [cannot use] | 12 MB | 59 ms | 0.87 μs/ip |
Use ip-location-db database
You can use ip-location-db database with the environment variable IP_LOCATION_DB
or CLI parameter --ip_location_db=XXXXX
. For example, if you want to use geolite2-geo-whois-asn-country
which supports wider ip than geolite2-country
, you can update the database by executing npm run updatedb --ip_location_db=geolite2-geo-whois-asn
.
If you cannot use GeoLite2 licence for your use-case, the licence issue can be circumvented by replacing the database in ip-location-db, as there are also some Public licenced (CC0 PDDL) databases in ip-location-db.
Custom Directory for database files
You can store the database files in custom directory with the environment variable GEOIP_DATADIR
or CLI parameter --geoip_datadir=XXXXX
.
For creating or updating the database files in custom directory, you need to run built-in updater as documented above with setting the environment variable GEOIP_DATADIR
or CLI parameter --geoip_datadir=XXXXX
.
If you have no write-access to the geoip-country
directory, it would be better to set the environment GEOIP_TMPDATADIR
or CLI parameter --geoip_tmpdatadir=YYYYY
for temporary directory when updating the database files.
License and EULA
Please carefully read the LICENSE and EULA files. This package comes with certain restrictions and obligations, most notably:
- You cannot prevent the library from updating the databases.
- You cannot use the GeoLite2 data:
- for FCRA purposes,
- to identify specific households or individuals.
You can read the latest version of GeoLite2 EULA. GeoLite2 database is provided under CC BY-SA 4.0 by MaxMind, so, you must create attribusion to MaxMind for using GeoLite2 database.
The license for the software itself is an Apache License 2.0 by geoip-country. This software is created from the repository geoip-lite/node-geoip. The software license of geoip-lite/node-geoip is Apache License 2.0.
References
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
22 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
packaging workflow detected
Details
- Info: Project packages its releases by way of GitHub Actions.: .github/workflows/release-v4.yml:7
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Warn: project license file does not contain an FSF or OSI license.
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/release-v4.yml:1
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Info: no jobLevel write permissions found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release-v4.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/sapics/geoip-country/release-v4.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release-v4.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/sapics/geoip-country/release-v4.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release-v4.yml:35: update your workflow using https://app.stepsecurity.io/secureworkflow/sapics/geoip-country/release-v4.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/sapics/geoip-country/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/sapics/geoip-country/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/sapics/geoip-country/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/sapics/geoip-country/test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/sapics/geoip-country/test.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/release-v4.yml:22
- Warn: npmCommand not pinned by hash: .github/workflows/release.yml:20
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:25
- Info: 0 out of 6 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
- Info: 0 out of 3 npmCommand dependencies pinned
Score
4.7
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to geoip-country
@types/geoip-country
TypeScript definitions for geoip-country
geoip-country-lookup
Lite version of GeoIP MaxMind module.
turbo-geoip-country
An updated, performance-focused fork of node-geoip with only country data
geoip-country-lite
A fork of GeoIP-lite, a light-weight, native JavaScript implementation of GeoIP API from MaxMind that only supports country data.