geoip-lite2 2.0.3 β 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitignore +3 -0
- package/AUTHORS +2 -0
- package/README.md +46 -26
- package/index.d.ts +23 -0
- package/lib/geoip.js +1 -533
- package/package.json +37 -28
- package/data/city.checksum +0 -1
- package/data/country.checksum +0 -1
- package/data/geoip-city-names.dat +0 -0
- package/data/geoip-city.dat +0 -0
- package/data/geoip-city6.dat +0 -0
- package/data/geoip-country.dat +0 -0
- package/data/geoip-country6.dat +0 -0
- package/lib/fsWatcher.js +0 -78
- package/lib/utils.js +0 -87
- package/scripts/updatedb.js +0 -627
- package/test/geo-lookup.js +0 -56
- package/test/main.js +0 -249
- package/test/memory_usage.js +0 -4
- package/test/one.js +0 -6
package/.gitignore
ADDED
package/AUTHORS
ADDED
package/README.md
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
πΊοΈ GeoIP-Lite2
|
|
1
|
+
πΊοΈ GeoIP-Lite2 v2.1 - Now even faster!
|
|
2
2
|
==========
|
|
3
|
-
A native
|
|
3
|
+
A native Node.js API for the GeoLite data from MaxMind.
|
|
4
4
|
|
|
5
|
-
This product includes GeoLite data created by MaxMind, available from https://www.maxmind.com
|
|
5
|
+
This product includes GeoLite data created by MaxMind, available from: https://www.maxmind.com
|
|
6
6
|
|
|
7
|
-
>
|
|
8
|
-
|
|
7
|
+
<a href="https://www.npmjs.com/package/geoip-lite2" target="_blank" title="geoip-lite2 - npm" style="text-decoration:none">
|
|
8
|
+
<img src="https://img.shields.io/npm/dt/geoip-lite2?maxAge=3600" alt="The number of downloads">
|
|
9
|
+
<img src="https://img.shields.io/github/last-commit/sefinek24/geoip-lite2" alt="Last commit">
|
|
10
|
+
<img src="https://img.shields.io/github/issues/sefinek24/geoip-lite2" alt="Issues">
|
|
11
|
+
<img src="https://img.shields.io/github/commit-activity/w/sefinek24/geoip-lite2" alt="Commit activity">
|
|
12
|
+
<img src="https://img.shields.io/github/languages/code-size/sefinek24/geoip-lite2" alt="Code size">
|
|
13
|
+
</a>
|
|
9
14
|
|
|
10
15
|
π Improved GeoIP Module by [Sefinek](https://sefinek.net)
|
|
11
16
|
------------
|
|
@@ -14,11 +19,19 @@ This module is an improved and updated edition of [geoip-lite](https://github.co
|
|
|
14
19
|
All components have undergone meticulous updates to ensure peak performance and functionality.
|
|
15
20
|
Notably, it is now powered by the most up-to-date MaxMind database, offering significantly enhanced accuracy and reliability. This translates to approximately 40% more precise geolocation data for any IP address, compared to the previous version which relied on a database from 2019.
|
|
16
21
|
|
|
22
|
+
Now this module operates even faster because its files have been minified!
|
|
23
|
+
|
|
17
24
|
Furthermore, the testing process has been improved by adopting the testing library Mocha.
|
|
18
25
|
This change enhances testing and contributes to the overall reliability of the module.
|
|
19
26
|
|
|
20
27
|
> I am not the creator of this npm module! All copyright rights belong to its original [Creators](AUTHORS).
|
|
21
28
|
|
|
29
|
+
β¨ Demonstration
|
|
30
|
+
------------
|
|
31
|
+
You can see this module in action on my official API. Generally speaking, the API interface is public, and you can safely use it in your projects. Happy coding!
|
|
32
|
+
|
|
33
|
+
> Endpoint : https://api.sefinek.net/api/v2/geoip/{ip}
|
|
34
|
+
> Example : https://api.sefinek.net/api/v2/geoip/109.207.159.255
|
|
22
35
|
|
|
23
36
|
π Introduction
|
|
24
37
|
------------
|
|
@@ -26,12 +39,15 @@ MaxMind provides a set of data files for IP to Geo mapping along with opensource
|
|
|
26
39
|
One would typically write a wrapper around their C API to get access to this data in other languages (like JavaScript).
|
|
27
40
|
|
|
28
41
|
GeoIP-Lite instead attempts to be a fully native JavaScript library. A converter script converts the CSV files from MaxMind into
|
|
29
|
-
an internal binary format (note that this is different from the binary data format provided by MaxMind). The
|
|
42
|
+
an internal binary format (note that this is different from the binary data format provided by MaxMind). The geo-ip module uses this
|
|
30
43
|
binary file to lookup IP addresses and return the country, region and city that it maps to.
|
|
31
44
|
|
|
32
45
|
Both IPv4 and IPv6 addresses are supported, however since the GeoLite IPv6 database does not currently contain any city or region
|
|
33
46
|
information, city, region and postal code lookups are only supported for IPv4.
|
|
34
47
|
|
|
48
|
+
> **Warning**
|
|
49
|
+
> **You MUST update the data files after installation.** The MaxMind license does not allow us to distribute the latest version of the data files with this package. Follow the instructions under update the datafiles for details.
|
|
50
|
+
|
|
35
51
|
|
|
36
52
|
π Philosophy
|
|
37
53
|
----------
|
|
@@ -41,7 +57,7 @@ My prime motivator was the fact that it was really hard to get libgeoip built fo
|
|
|
41
57
|
|
|
42
58
|
π΅οΈββοΈ Why GeoIP-Lite?
|
|
43
59
|
-------------
|
|
44
|
-
GeoIP-Lite is a fully JavaScript implementation of the MaxMind
|
|
60
|
+
GeoIP-Lite is a fully JavaScript implementation of the MaxMind GeoIP API. It is not as fully featured as bindings that use `libgeoip`.
|
|
45
61
|
By reducing scope, this package is about 40% faster at doing lookups. On average, an IP to Location lookup should take 20 microseconds on
|
|
46
62
|
a Macbook Pro. IPv4 addresses take about 6 microseconds, while IPv6 addresses take about 30 microseconds.
|
|
47
63
|
|
|
@@ -82,17 +98,19 @@ npm install geoip-lite2
|
|
|
82
98
|
```
|
|
83
99
|
|
|
84
100
|
### 2. Update the datafiles (optional)
|
|
85
|
-
Run `cd node_modules/geoip-lite2 && npm run
|
|
101
|
+
Run `cd node_modules/geoip-lite2 && npm run updatedb license_key=YOUR_LICENSE_KEY` to update the data files. (Replace `YOUR_LICENSE_KEY` with your license key obtained from [maxmind.com](https://support.maxmind.com/hc/en-us/articles/4407111582235-Generate-a-License-Key))
|
|
86
102
|
|
|
87
|
-
You can create maxmind account [here](https://www.maxmind.com/en/geolite2/signup)
|
|
103
|
+
You can create maxmind account [here](https://www.maxmind.com/en/geolite2/signup).
|
|
88
104
|
|
|
89
|
-
**
|
|
90
|
-
|
|
105
|
+
> **Note**
|
|
106
|
+
> This requires a lot of RAM. It is known to fail on a Digital Ocean or AWS micro instance.
|
|
107
|
+
> There are no plans to change this. GeoIP-Lite2 stores all data in RAM in order to be fast.
|
|
108
|
+
> If you need an external API that provides GeoIP, you can use [this](#-demonstration).
|
|
91
109
|
|
|
92
110
|
|
|
93
111
|
π§© API
|
|
94
112
|
---
|
|
95
|
-
|
|
113
|
+
GeoIP-Lite2 is completely synchronous. There are no callbacks involved.
|
|
96
114
|
All blocking file IO is done at startup time, so all runtime calls are executed in-memory and are fast.
|
|
97
115
|
Startup may take up to 200ms while it reads into memory and indexes data files.
|
|
98
116
|
|
|
@@ -176,7 +194,7 @@ You can do it programmatically, calling after scheduled data updates
|
|
|
176
194
|
geoip.reloadDataSync();
|
|
177
195
|
|
|
178
196
|
// Asynchronously
|
|
179
|
-
geoip.reloadData(
|
|
197
|
+
geoip.reloadData(() => {
|
|
180
198
|
console.log('Done');
|
|
181
199
|
});
|
|
182
200
|
```
|
|
@@ -198,25 +216,27 @@ however it is the best available for free. You can use the commercial GeoIP data
|
|
|
198
216
|
accuracy by buying a license from MaxMind, and then using the conversion utility to convert it to a format that
|
|
199
217
|
GeoIP-Lite understands. You will need to use the `.csv` files from MaxMind for conversion.
|
|
200
218
|
|
|
201
|
-
Also note that on
|
|
219
|
+
Also note that on occasion, the library may take up to 5 seconds to load into memory. This is largely dependent on
|
|
202
220
|
how busy your disk is at that time. It can take as little as 200ms on a lightly loaded disk. This is a one time
|
|
203
221
|
cost though, and you make it up at run time with very fast lookups.
|
|
204
222
|
|
|
205
223
|
### Memory usage
|
|
206
|
-
Quick test on memory consumption shows that library uses around 100Mb per process
|
|
224
|
+
Quick test on memory consumption shows that library uses around 100Mb per process.
|
|
207
225
|
|
|
208
226
|
```javascript
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
227
|
+
const geoip2 = require('geoip-lite2');
|
|
228
|
+
console.log(process.memoryUsage());
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Output:
|
|
232
|
+
* {
|
|
233
|
+
* rss: 126365696,
|
|
234
|
+
* heapTotal: 7753728,
|
|
235
|
+
* heapUsed: 5844880,
|
|
236
|
+
* external: 164098897,
|
|
237
|
+
* arrayBuffers: 163675390
|
|
238
|
+
* }
|
|
239
|
+
**/
|
|
220
240
|
```
|
|
221
241
|
|
|
222
242
|
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare module 'geoip-lite2' {
|
|
2
|
+
export const cmp: number | any | null
|
|
3
|
+
|
|
4
|
+
export type GeoData = {
|
|
5
|
+
range: [number, number];
|
|
6
|
+
country: string;
|
|
7
|
+
region: string;
|
|
8
|
+
eu: string;
|
|
9
|
+
timezone: string;
|
|
10
|
+
city: string;
|
|
11
|
+
ll: [number, number];
|
|
12
|
+
metro: number;
|
|
13
|
+
area: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function lookup(ip: string): GeoData | null;
|
|
17
|
+
|
|
18
|
+
export const pretty: (n: string | number | number[]) => string;
|
|
19
|
+
export const startWatchingDataUpdate: (callback: () => void) => void;
|
|
20
|
+
export const reloadDataSync: () => void;
|
|
21
|
+
export const reloadData: (callback: () => void) => void;
|
|
22
|
+
export const version: string;
|
|
23
|
+
}
|