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
Copy file name to clipboardExpand all lines: README.md
+11-18Lines changed: 11 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,7 +72,8 @@ You can see this module in action using my [official API](https://api.sefinek.ne
72
72
73
73
74
74
## 📚 Library API
75
-
GeoIP-Lite2 is completely synchronous. It does not use callbacks. All blocking file I/O is performed at startup, so all runtime calls are executed in-memory and are fast.
75
+
GeoIP-Lite2 performs lookups synchronously in memory (`lookup`). It also provides async data reload methods (`reloadData`) and file watcher callbacks (`startWatchingDataUpdate`).
76
+
All blocking file I/O is performed at startup, so all runtime lookups are fast.
76
77
Startup may take up to 200 ms while reading and indexing data files into memory.
77
78
78
79
### Looking up an IP address
@@ -104,17 +105,6 @@ If the IP address was found, the `lookup` method returns an object with the foll
104
105
105
106
If the IP address was not found, `lookup` returns `null`.
106
107
107
-
### Pretty printing an IP address
108
-
If you have a 32-bit unsigned integer or a number returned as part of the `range` array,
109
-
you can use the `pretty` method to get a human-readable format.
110
-
111
-
```js
112
-
console.log('IP is %s', geoIp.pretty(ip));
113
-
```
114
-
115
-
The method returns a string if the input format is recognized, otherwise it returns the input itself.
116
-
117
-
118
108
## 🔄 Built-in Updater
119
109
This package contains an update script that downloads files from MaxMind and handles CSV conversion.
120
110
A npm script alias has been configured to simplify this process. Internet access is required and MaxMind download limits apply.
@@ -144,10 +134,13 @@ You can do it programmatically, calling after scheduled data updates
144
134
// Synchronously
145
135
geoIp.reloadDataSync();
146
136
147
-
// Asynchronously
137
+
// Asynchronously (callback)
148
138
geoIp.reloadData(() => {
149
139
console.log('Done');
150
140
});
141
+
142
+
// Asynchronously (Promise)
143
+
awaitgeoIp.reloadData();
151
144
```
152
145
153
146
#### Automatic Start and stop watching for data updates
@@ -163,11 +156,11 @@ This tool can be used with `npm run updatedb` to periodically update geo data on
163
156
The following environment variables can be set.
164
157
165
158
```bash
166
-
# Override the default node_modules/geoip-lite/data dir
167
-
GEOTMPDIR=/some/path
168
-
169
-
# Override the default node_modules/geoip-lite/tmp dir
159
+
# Override the default node_modules/geoip-lite2/data dir
170
160
GEODATADIR=/some/path
161
+
162
+
# Override the default node_modules/geoip-lite2/tmp dir
0 commit comments