You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let lookup =geolite2.open('GeoLite2-City', path=> {
55
-
let buf =fs.readFileSync(path);
56
-
returnnewmaxmind.Reader(buf);
57
-
});
55
+
geolite2.downloadDbs().then(() => {
56
+
let lookup =geolite2.open('GeoLite2-City', path=> {
57
+
let buf =fs.readFileSync(path);
58
+
returnnewmaxmind.Reader(buf);
59
+
});
58
60
59
-
let city =lookup.get('66.6.44.4');
61
+
let city =lookup.get('66.6.44.4');
60
62
61
-
lookup.close();
63
+
lookup.close();
64
+
})
62
65
```
63
66
64
67
### Advanced usage
65
68
66
-
If you do not consume the databases directly, or need more flexible methods, the internal `geolite2.UpdateSubscriber` class is exposed so you can directly listen to database update events.
69
+
If you do not consume the databases directly, or need more flexible methods, the internal `geolite2.UpdateSubscriber` class is exposed so you can directly listen to database update events. You can also choose where to download the databases.
67
70
68
71
Example usage:
69
72
```javascript
70
73
constgeolite2=require('geolite2-redist');
71
74
75
+
constdbBasePath='/tmp/maxmind'
76
+
72
77
functionuseGeolite() {
73
-
// You can retrieve the path to `.mmdb` files
74
-
let cityPath =geolite2.paths['GeoLite2-City'];
78
+
// Do something with the databases
75
79
}
76
80
81
+
awaitgeolite2.downloadDbs(dbBasePath)
82
+
77
83
constdbWatcher=newgeolite2.UpdateSubscriber();
78
84
dbWatcher.on('update', () => {
79
85
useGeolite();
@@ -92,6 +98,7 @@ import geolite2 from 'geolite2-redist';
92
98
importmaxmind, { CityResponse } from'maxmind';
93
99
94
100
(async () => {
101
+
awaitgeolite2.downloadDbs()
95
102
let lookup =awaitgeolite2.open<CityResponse>('GeoLite2-City', path=> {
0 commit comments