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
The library uses the `net` module for IP validation, making it
Node-only. Updated the README to drop the inaccurate browser support
claim, document the Node 18+ requirement, use modern async/await
examples, and add a TypeScript section listing exported types.
https://claude.ai/code/session_01UabaLo3R3sXovyxaZo2yCF
JavaScript library that can be used in a web browser or Node.js application to gather information for an IP address using https://ipdata.co.
5
+
A Node.js library for the [ipdata](https://ipdata.co) API. Look up IP addresses for geolocation, threat intelligence, company data, and more.
6
+
7
+
Requires **Node.js 18** or later. Uses the native `fetch` API with zero HTTP dependencies.
6
8
7
9
**Table of Contents**
8
10
@@ -14,18 +16,17 @@ JavaScript library that can be used in a web browser or Node.js application to g
14
16
-[Lookup](#lookup)
15
17
-[Bulk Lookup](#bulk-lookup)
16
18
-[Response Fields](#response-fields)
19
+
-[TypeScript](#typescript)
17
20
18
21
## Install
19
22
20
23
```sh
21
-
$ npm install ipdata
24
+
npm install ipdata
22
25
```
23
26
24
27
## Use
25
28
26
-
### Import library
27
-
28
-
Import the library.
29
+
### Import Library
29
30
30
31
```js
31
32
importIPDatafrom'ipdata';
@@ -37,148 +38,126 @@ A named export is also available:
37
38
import { IPData } from'ipdata';
38
39
```
39
40
40
-
If you are using `require()`:
41
+
CommonJS:
41
42
42
43
```js
43
44
const { IPData } =require('ipdata');
44
45
```
45
46
46
47
### Create an Instance
47
48
48
-
Create an instance of the `IPData` class and pass your api key for IPData as the first parameter.
49
+
Create an instance of the `IPData` class with your [API key](https://ipdata.co/).
49
50
50
51
```js
51
52
constipdata=newIPData('<apiKey>');
52
53
```
53
54
54
-
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.
55
+
#### Caching
56
+
57
+
The library caches up to 4096 responses for 24 hours using an LRU cache by default. You can configure the cache by passing an options object as the second parameter.
55
58
56
59
```js
57
-
constcacheConfig= {
58
-
max:1000, // max size
59
-
ttl:10*60*1000, // time-to-live in ms (i.e. 10 minutes)
60
-
};
61
-
constipdata=newIPData('<apiKey>', cacheConfig);
60
+
constipdata=newIPData('<apiKey>', {
61
+
max:1000, // max number of entries
62
+
ttl:10*60*1000, // 10 minutes
63
+
});
62
64
```
63
65
64
-
**Note:**To disable the cache pass `1` as the `ttl` (1ms effectively disables caching).
66
+
To disable caching, set `ttl` to `1`:
65
67
66
68
```js
67
-
constcacheConfig= {
68
-
ttl:1, // disable the cache
69
-
};
70
-
constipdata=newIPData('<apiKey>', cacheConfig);
69
+
constipdata=newIPData('<apiKey>', { ttl:1 });
71
70
```
72
71
73
72
### EU Endpoint
74
73
75
-
By default requests are routed to the global endpoint (`https://api.ipdata.co`). To ensure enduser data stays in the EU, pass the EU endpoint as the third parameter.
74
+
By default requests are routed to the global endpoint (`https://api.ipdata.co`). To ensure end-user data stays in the EU, pass the EU endpoint as the third parameter.
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.
The `company` field returns an object with `name`, `domain`, `network`, and `type` properties.
149
+
**`asn`** — `{ asn, name, domain, route, type }`
150
+
151
+
**`company`** — `{ name, domain, network, type }`
181
152
182
-
The `carrier` field returns an object with `name`, `mcc`, and `mnc` properties.
153
+
**`carrier`** — `{ name, mcc, mnc }`
183
154
184
-
The `threat` field returns an object with `is_tor`, `is_icloud_relay`, `is_proxy`, `is_datacenter`, `is_anonymous`, `is_known_attacker`, `is_known_abuser`, `is_threat`, `is_bogon`, and `blocklists` properties.
0 commit comments