geoip-lite
Advanced tools
Comparing version 1.3.6 to 1.3.7
@@ -36,3 +36,3 @@ var fs = require('fs'); | ||
var cache4 = { | ||
var conf4 = { | ||
firstIP: null, | ||
@@ -47,3 +47,3 @@ lastIP: null, | ||
var cache6 = { | ||
var conf6 = { | ||
firstIP: null, | ||
@@ -56,2 +56,6 @@ lastIP: null, | ||
//copy original configs | ||
var cache4 = JSON.parse(JSON.stringify(conf4)); | ||
var cache6 = JSON.parse(JSON.stringify(conf6)); | ||
var RECORD_SIZE = 10; | ||
@@ -231,11 +235,3 @@ var RECORD_SIZE6 = 34; | ||
var datSize; | ||
var asyncCache = { | ||
firstIP: null, | ||
lastIP: null, | ||
lastLine: 0, | ||
locationBuffer: null, | ||
locationRecordSize: 64, | ||
mainBuffer: null, | ||
recordSize: 12 | ||
}; | ||
var asyncCache = JSON.parse(JSON.stringify(conf4)); | ||
@@ -319,2 +315,3 @@ //when the preload function receives a callback, do the task asynchronously | ||
asyncCache.lastIP = asyncCache.mainBuffer.readUInt32BE((asyncCache.lastLine * asyncCache.recordSize) + 4); | ||
asyncCache.firstIP = asyncCache.mainBuffer.readUInt32BE(0); | ||
cache4 = asyncCache; | ||
@@ -367,9 +364,3 @@ } | ||
var datSize; | ||
var asyncCache6 = { | ||
firstIP: null, | ||
lastIP: null, | ||
lastLine: 0, | ||
mainBuffer: null, | ||
recordSize: 58 | ||
}; | ||
var asyncCache6 = JSON.parse(JSON.stringify(conf6)); | ||
@@ -521,2 +512,8 @@ //when the preload function receives a callback, do the task asynchronously | ||
}, | ||
//clear data | ||
clear: function () { | ||
cache4 = JSON.parse(JSON.stringify(conf4)); | ||
cache6 = JSON.parse(JSON.stringify(conf6)); | ||
}, | ||
@@ -523,0 +520,0 @@ // Reload data synchronously |
{ | ||
"name" : "geoip-lite", | ||
"version" : "1.3.6", | ||
"version" : "1.3.7", | ||
"description" : "A light weight native JavaScript implementation of GeoIP API from MaxMind", | ||
@@ -22,3 +22,2 @@ "keywords" : ["geo", "geoip", "ip", "ipv4", "ipv6", "geolookup", "maxmind", "geolite"], | ||
"colors": "^1.1.2", | ||
"eslint": "^5.12.1", | ||
"iconv-lite": "^0.4.13", | ||
@@ -34,2 +33,3 @@ "ip-address": "^5.8.9", | ||
"devDependencies": { | ||
"eslint": "^5.12.1", | ||
"nodeunit": "^0.11.2" | ||
@@ -36,0 +36,0 @@ }, |
@@ -70,3 +70,3 @@ GeoIP-lite | ||
Run `npm run-script updatedb` to update the data files. | ||
Run `cd node_modules/geoip-lite && npm run-script updatedb` to update the data files. | ||
@@ -128,15 +128,37 @@ **NOTE** that this requires a lot of RAM. It is known to fail on on a Digital Ocean or AWS micro instance. | ||
### Start and stop watching for data updates ### | ||
Built-in Updater | ||
---------------- | ||
If you have a server running `geoip-lite`, and you want to update its geo data without a restart, you can enable | ||
the data watcher to automatically refresh in-memory geo data when a file changes in the data directory. | ||
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. | ||
```javascript | ||
geoip.startWatchingDataUpdate(); | ||
Package stores checksums of MaxMind data and by default only downloads them if checksums have changed. | ||
### Ways to update data ### | ||
```shell | ||
#update data if new data is available | ||
npm run-script updatedb | ||
#force udpate data even if checkums have not changed | ||
npm run-script updatedb force | ||
``` | ||
This tool can be used with `npm run-script updatedb` to periodically update geo data on a running server. | ||
You can also run it by doing: | ||
Additionally, if you schedule upgrades, you can programmatically make geoip reload the data from new database | ||
```bash | ||
node ./node_modules/geoip-lite/scripts/updatedb.js | ||
``` | ||
Or, if you really want, run the update once by `require('geoip-lite/scripts/updatedb.js')`. | ||
### Ways to reload data in your app when update finished ### | ||
If you have a server running `geoip-lite`, and you want to reload its geo data, after you finished update, without a restart. | ||
#### Programmatically #### | ||
You can do it programmatically, calling after scheduled data updates | ||
```javascript | ||
@@ -152,22 +174,12 @@ //Synchronously | ||
#### Automatic Start and stop watching for data updates #### | ||
Built-in Updater | ||
---------------- | ||
You can enable the data watcher to automatically refresh in-memory geo data when a file changes in the data directory. | ||
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. | ||
```shell | ||
npm run-script updatedb | ||
```javascript | ||
geoip.startWatchingDataUpdate(); | ||
``` | ||
You can also run it by doing: | ||
This tool can be used with `npm run-script updatedb` to periodically update geo data on a running server. | ||
```bash | ||
node ./node_modules/geoip-lite/scripts/updatedb.js | ||
``` | ||
Or, if you really want, run the update once by `require('geoip-lite/scripts/updatedb.js')`. | ||
Caveats | ||
@@ -185,2 +197,20 @@ ------- | ||
### Memory usage ### | ||
Quick test on memory consumption shows that library uses around 100Mb per process | ||
```javascript | ||
var geoip = require('geoip-lite'); | ||
console.log(process.memoryUsage()); | ||
/** | ||
* Outputs: | ||
* { | ||
* rss: 126365696, | ||
* heapTotal: 10305536, | ||
* heapUsed: 5168944, | ||
* external: 104347120 | ||
* } | ||
**/ | ||
``` | ||
References | ||
@@ -187,0 +217,0 @@ ---------- |
@@ -8,2 +8,3 @@ // fetches and converts maxmind lite databases | ||
var fs = require('fs'); | ||
var http = require('http'); | ||
var https = require('https'); | ||
@@ -164,3 +165,3 @@ var path = require('path'); | ||
if (status !== 200) { | ||
console.log('ERROR'.red + ': HTTP Request Failed [%d %s]', status, https.STATUS_CODES[status]); | ||
console.log('ERROR'.red + ': HTTP Request Failed [%d %s]', status, http.STATUS_CODES[status]); | ||
client.abort(); | ||
@@ -226,3 +227,3 @@ process.exit(); | ||
if (status !== 200) { | ||
console.log('ERROR'.red + ': HTTP Request Failed [%d %s]', status, https.STATUS_CODES[status]); | ||
console.log('ERROR'.red + ': HTTP Request Failed [%d %s]', status, http.STATUS_CODES[status]); | ||
client.abort(); | ||
@@ -229,0 +230,0 @@ process.exit(); |
@@ -66,3 +66,3 @@ var geoip = require('../lib/geoip'); | ||
test.strictEqual(actual.city, 'Amsterdam', "should match city"); | ||
test.strictEqual(actual.city, 'Badhoevedorp', "should match city"); | ||
@@ -73,3 +73,3 @@ test.ok(actual.ll, 'should contain coordinates'); | ||
test.strictEqual(actual.area, 50, "should match area"); | ||
test.strictEqual(actual.area, 10, "should match area"); | ||
@@ -82,3 +82,3 @@ test.done(); | ||
var ip = "95.17.102.184"; | ||
var ip = "2.139.175.1"; | ||
var expected = "Logroño"; | ||
@@ -98,3 +98,3 @@ var actual = geoip.lookup(ip); | ||
test.equal(actual.city, "Perris");//keeps changing with each update from one city to other (close to each other geographically) | ||
test.equal(actual.city, "Nuevo");//keeps changing with each update from one city to other (close to each other geographically) | ||
test.equal(actual.metro, 803); | ||
@@ -114,3 +114,64 @@ | ||
test.done(); | ||
}, | ||
testSyncReload: function (test) { | ||
test.expect(6); | ||
//get original data | ||
var before4 = geoip.lookup("75.82.117.180"); | ||
test.notEqual(before4, null); | ||
var before6 = geoip.lookup("::ffff:173.185.182.82"); | ||
test.notEqual(before6, null); | ||
//clear data; | ||
geoip.clear(); | ||
//make sure data is cleared | ||
var none4 = geoip.lookup("75.82.117.180"); | ||
test.equal(none4, null); | ||
var none6 = geoip.lookup("::ffff:173.185.182.82"); | ||
test.equal(none6, null); | ||
//reload data synchronized | ||
geoip.reloadDataSync(); | ||
//make sure we have value from before | ||
var after4 = geoip.lookup("75.82.117.180"); | ||
test.deepEqual(before4, after4); | ||
var after6 = geoip.lookup("::ffff:173.185.182.82"); | ||
test.deepEqual(before6, after6); | ||
test.done(); | ||
}, | ||
testAsyncReload: function (test) { | ||
test.expect(6); | ||
//get original data | ||
var before4 = geoip.lookup("75.82.117.180"); | ||
test.notEqual(before4, null); | ||
var before6 = geoip.lookup("::ffff:173.185.182.82"); | ||
test.notEqual(before6, null); | ||
//clear data; | ||
geoip.clear(); | ||
//make sure data is cleared | ||
var none4 = geoip.lookup("75.82.117.180"); | ||
test.equal(none4, null); | ||
var none6 = geoip.lookup("::ffff:173.185.182.82"); | ||
test.equal(none6, null); | ||
//reload data asynchronously | ||
geoip.reloadData(function(){ | ||
//make sure we have value from before | ||
var after4 = geoip.lookup("75.82.117.180"); | ||
test.deepEqual(before4, after4); | ||
var after6 = geoip.lookup("::ffff:173.185.182.82"); | ||
test.deepEqual(before6, after6); | ||
test.done(); | ||
}); | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
113257428
7
17
1313
228
2
10
- Removedeslint@^5.12.1
- Removed@babel/code-frame@7.26.2(transitive)
- Removed@babel/helper-validator-identifier@7.25.9(transitive)
- Removedacorn@6.4.2(transitive)
- Removedacorn-jsx@5.3.2(transitive)
- Removedajv@6.12.6(transitive)
- Removedansi-escapes@3.2.0(transitive)
- Removedansi-regex@3.0.14.1.1(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedargparse@1.0.10(transitive)
- Removedastral-regex@1.0.0(transitive)
- Removedcallsites@3.1.0(transitive)
- Removedchalk@2.4.2(transitive)
- Removedchardet@0.7.0(transitive)
- Removedcli-cursor@2.1.0(transitive)
- Removedcli-width@2.2.1(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedcross-spawn@6.0.6(transitive)
- Removeddebug@4.4.0(transitive)
- Removeddeep-is@0.1.4(transitive)
- Removeddoctrine@3.0.0(transitive)
- Removedemoji-regex@7.0.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedeslint@5.16.0(transitive)
- Removedeslint-scope@4.0.3(transitive)
- Removedeslint-utils@1.4.3(transitive)
- Removedeslint-visitor-keys@1.3.0(transitive)
- Removedespree@5.0.1(transitive)
- Removedesprima@4.0.1(transitive)
- Removedesquery@1.6.0(transitive)
- Removedesrecurse@4.3.0(transitive)
- Removedestraverse@4.3.05.3.0(transitive)
- Removedesutils@2.0.3(transitive)
- Removedexternal-editor@3.1.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedfast-levenshtein@2.0.6(transitive)
- Removedfigures@2.0.0(transitive)
- Removedfile-entry-cache@5.0.1(transitive)
- Removedflat-cache@2.0.1(transitive)
- Removedflatted@2.0.2(transitive)
- Removedfunctional-red-black-tree@1.0.1(transitive)
- Removedglobals@11.12.0(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedignore@4.0.6(transitive)
- Removedimport-fresh@3.3.0(transitive)
- Removedimurmurhash@0.1.4(transitive)
- Removedinquirer@6.5.2(transitive)
- Removedis-fullwidth-code-point@2.0.0(transitive)
- Removedisexe@2.0.0(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedjs-yaml@3.14.1(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stable-stringify-without-jsonify@1.0.1(transitive)
- Removedlevn@0.3.0(transitive)
- Removedmimic-fn@1.2.0(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removedms@2.1.3(transitive)
- Removedmute-stream@0.0.7(transitive)
- Removednatural-compare@1.4.0(transitive)
- Removednice-try@1.0.5(transitive)
- Removedonetime@2.0.1(transitive)
- Removedoptionator@0.8.3(transitive)
- Removedos-tmpdir@1.0.2(transitive)
- Removedparent-module@1.0.1(transitive)
- Removedpath-is-inside@1.0.2(transitive)
- Removedpath-key@2.0.1(transitive)
- Removedpicocolors@1.1.1(transitive)
- Removedprelude-ls@1.1.2(transitive)
- Removedprogress@2.0.3(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedregexpp@2.0.1(transitive)
- Removedresolve-from@4.0.0(transitive)
- Removedrestore-cursor@2.0.0(transitive)
- Removedrimraf@2.6.3(transitive)
- Removedrun-async@2.4.1(transitive)
- Removedrxjs@6.6.7(transitive)
- Removedsemver@5.7.2(transitive)
- Removedshebang-command@1.2.0(transitive)
- Removedshebang-regex@1.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedslice-ansi@2.1.0(transitive)
- Removedsprintf-js@1.0.3(transitive)
- Removedstring-width@2.1.13.1.0(transitive)
- Removedstrip-ansi@4.0.05.2.0(transitive)
- Removedstrip-json-comments@2.0.1(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedtable@5.4.6(transitive)
- Removedtext-table@0.2.0(transitive)
- Removedthrough@2.3.8(transitive)
- Removedtmp@0.0.33(transitive)
- Removedtslib@1.14.1(transitive)
- Removedtype-check@0.3.2(transitive)
- Removeduri-js@4.4.1(transitive)
- Removedwhich@1.3.1(transitive)
- Removedword-wrap@1.2.5(transitive)
- Removedwrite@1.0.3(transitive)