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
JavaScript library that can be used in a web browser or Node.js application to gather information using https://ipdata.co.
6
6
7
7
**Table of Contents**
8
+
8
9
-[Install](#install)
9
10
-[Import the library](#import-the-library)
10
11
-[Use](#use)
11
-
*[Lookup](#lookup)
12
-
*[Lookup Bulk](#lookup-bulk)
13
-
12
+
-[Lookup](#lookup)
13
+
-[Lookup Bulk](#lookup-bulk)
14
14
15
15
## Install
16
16
@@ -32,76 +32,83 @@ Create an instance of the `IPData` class and pass your api key for IPData as the
32
32
constipdata=newIPData('<apiKey>');
33
33
```
34
34
35
-
The library will cache responses using the `lookup()` method for 24 hours using a LRU cache. You can turn off the cache by passing `false` as the second parameter to the constructor.
35
+
The library will cache 4096 ip addresses responses for 24 hours using a LRU cache by default. You can configure the cache by passing an object as the second paramenter.
36
+
37
+
```js
38
+
constcacheConfig= {
39
+
max:1000, // max size
40
+
maxAge:10*60*1000, // max age in ms (i.e. 10 minutes)
41
+
};
42
+
constipdata=newIPData('<apiKey>', cacheConfig);
43
+
```
44
+
45
+
**Note:** To disable the cache pass `-1` as the `maxAge`.
36
46
37
47
```js
38
-
constipdata=newIPData('<apiKey>', false);
48
+
constcacheConfig= {
49
+
maxAge:-1, // disable the cache
50
+
};
51
+
constipdata=newIPData('<apiKey>', cacheConfig);
39
52
```
40
53
41
54
### Lookup
42
55
43
56
The library will lookup the ip address of the host computer if no ip address is provided.
44
57
45
58
```js
46
-
ipdata.lookup()
47
-
.then(function(info) {
48
-
// info.ip === '<hostcomputerip>'
49
-
// ...
50
-
});
59
+
ipdata.lookup().then(function(info) {
60
+
// info.ip === '<hostcomputerip>'
61
+
// ...
62
+
});
51
63
```
52
64
53
65
You can pass an ip address as the first parameter to the `lookup()` method to lookup information about the ip address using IPData.
54
66
55
67
```js
56
-
ipdata.lookup('1.1.1.1')
57
-
.then(function(info) {
58
-
// info.ip === 1.1.1.1
59
-
// ...
60
-
});
68
+
ipdata.lookup('1.1.1.1').then(function(info) {
69
+
// info.ip === 1.1.1.1
70
+
// ...
71
+
});
61
72
```
62
73
63
74
You can specify only a select field to be returned when looking up an ip address by passing a field as the second parameter to the `lookup()` method.
You can specify only certain fields to be returned when looking up an ip address by passing an array of fields as the third parameter to the `lookup()` method.
You can specify only certain fields to be returned when looking up multiple ip addresses by passing an array of fields as the second parameter to the `bulkLookup()` method.
0 commit comments