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
This is the official Node.js Express client library for the [IPinfo.io](https://ipinfo.io) IP address API, allowing you to look up your own IP address, or get any of the following details for an IP:
4
-
5
-
-[IP to geolocation](https://ipinfo.io/ip-geolocation-api) (city, region, country, postal code, latitude, and longitude)
6
-
-[IP to ASN](https://ipinfo.io/asn-api) (ISP or network operator, associated domain name, and type, such as business, hosting, or company)
7
-
-[IP to Company](https://ipinfo.io/ip-company-api) (the name and domain of the business that uses the IP address)
8
-
-[IP to Carrier](https://ipinfo.io/ip-carrier-api) (the name of the mobile carrier and MNC and MCC for that carrier if the IP is used exclusively for mobile traffic)
9
-
10
-
Check all the data we have for your IP address [here](https://ipinfo.io/what-is-my-ip).
3
+
This is the official Node.js Express client library for the
4
+
[IPinfo.io](https://ipinfo.io) IP address API, allowing you to look up your own
5
+
IP address, or get any of the following details for an IP:
6
+
7
+
-[IP to geolocation](https://ipinfo.io/ip-geolocation-api) (city, region,
8
+
country, postal code, latitude, and longitude)
9
+
-[IP to ASN](https://ipinfo.io/asn-api) (ISP or network operator, associated
10
+
domain name, and type, such as business, hosting, or company)
11
+
-[IP to Company](https://ipinfo.io/ip-company-api) (the name and domain of
12
+
the business that uses the IP address)
13
+
-[IP to Carrier](https://ipinfo.io/ip-carrier-api) (the name of the mobile
14
+
carrier and MNC and MCC for that carrier if the IP is used exclusively for
15
+
mobile traffic)
16
+
17
+
Check all the data we have for your IP address
18
+
[here](https://ipinfo.io/what-is-my-ip).
11
19
12
20
### Getting Started
13
21
14
-
You'll need an IPinfo API access token, which you can get by signing up for a free account at [https://ipinfo.io/signup](https://ipinfo.io/signup).
22
+
You'll need an IPinfo API access token, which you can get by signing up for a
23
+
free account at [https://ipinfo.io/signup](https://ipinfo.io/signup).
15
24
16
-
The free plan is limited to 50,000 requests per month, and doesn't include some of the data fields such as IP type and company data. To enable all the data fields and additional request volumes see [https://ipinfo.io/pricing](https://ipinfo.io/pricing)
25
+
The free plan is limited to 50,000 requests per month, and doesn't include some
26
+
of the data fields such as IP type and company data. To enable all the data
The library also supports the Lite API, see the [Lite API section](#lite-api) for more info.
30
+
The library also supports the Lite API, see the [Lite API section](#lite-api)
31
+
for more info.
19
32
20
33
### Installation
21
34
@@ -59,102 +72,127 @@ ipinfo({
59
72
The following is a full example of using the middleware function.
60
73
61
74
```javascript
62
-
constexpress=require('express')
63
-
constipinfo=require('ipinfo-express')
64
-
65
-
constapp=express()
66
-
app.use(ipinfo({
67
-
token:"token",
68
-
cache:null,
69
-
timeout:5000,
70
-
ipSelector:null
71
-
}))
72
-
73
-
app.get('/', function (req, res) {
74
-
res.send(req.ipinfo)
75
-
})
75
+
constexpress=require("express");
76
+
constipinfo=require("ipinfo-express");
77
+
78
+
constapp=express();
79
+
app.use(
80
+
ipinfo({
81
+
token:"token",
82
+
cache:null,
83
+
timeout:5000,
84
+
ipSelector:null
85
+
})
86
+
);
87
+
88
+
app.get("/", function (req, res) {
89
+
res.send(req.ipinfo);
90
+
});
76
91
77
92
app.listen(3000, () => {
78
-
console.log(`Server is running`)
79
-
})
93
+
console.log(`Server is running`);
94
+
});
80
95
```
81
96
82
97
### IP Selection Mechanism
83
98
84
99
By default, the IP from the incoming request object is used.
85
100
86
-
Since the desired IP by your system may be in other locations, the IP selection mechanism is configurable and some alternative built-in options are available.
101
+
Since the desired IP by your system may be in other locations, the IP selection
102
+
mechanism is configurable and some alternative built-in options are available.
87
103
88
104
#### Using built-in IP selectors
89
105
90
-
- Default IP Selector
91
-
- Originating IP Selector
106
+
-Default IP Selector
107
+
-Originating IP Selector
92
108
93
109
##### Default IP selector
94
110
95
-
A [defaultIPSelector](https://github.com/ipinfo/node-express/blob/master/src/ip-selector/default-ip-selector.js) function is used by default if no IP selection method is provided. It returns the default IP from the incoming request object of Express.
A [originatingIPSelector](https://github.com/ipinfo/node-express/blob/master/src/ip-selector/originating-ip-selector.js) selects an IP address by trying to extract it from the `X-Forwarded-For` header. This is not always the most reliable unless your proxy setup allows you to trust it. It will default to the source IP on the request if the header doesn't exist.
In case a custom IP selector is required, you may set your custom function to `ipSelector`. Your custom function should take [req](https://expressjs.com/en/api.html#req) as an argument and return an IP in `string` format.
163
+
In case a custom IP selector is required, you may set your custom function to
164
+
`ipSelector`. Your custom function should take
165
+
[req](https://expressjs.com/en/api.html#req) as an argument and return an IP in
166
+
`string` format.
134
167
135
168
For example:
136
169
137
170
```javascript
138
-
constipinfo=require('ipinfo-express')
139
-
140
-
constapp=express()
141
-
app.use(ipinfo({
142
-
token:"token",
143
-
cache:null,
144
-
timeout:5000,
145
-
ipSelector: (req) => {
146
-
ip =""
147
-
// update ip according to your logic and return the selected IP
148
-
return ip
149
-
}
150
-
}))
171
+
constipinfo=require("ipinfo-express");
172
+
173
+
constapp=express();
174
+
app.use(
175
+
ipinfo({
176
+
token:"token",
177
+
cache:null,
178
+
timeout:5000,
179
+
ipSelector: (req) => {
180
+
ip ="";
181
+
// update ip according to your logic and return the selected IP
182
+
return ip;
183
+
}
184
+
})
185
+
);
151
186
```
152
187
153
188
### Lite API
154
189
155
-
The library gives the possibility to use the [Lite API](https://ipinfo.io/developers/lite-api) too, authentication with your token is still required.
190
+
The library gives the possibility to use the
191
+
[Lite API](https://ipinfo.io/developers/lite-api) too, authentication with your
192
+
token is still required.
156
193
157
-
The IP details returned are slightly different from the Core API middleware, though the arguments are identical.
194
+
The IP details returned are slightly different from the Core API middleware,
195
+
though the arguments are identical.
158
196
159
197
```typescript
160
198
const { ipinfoLite } =require('ipinfo-express')
@@ -167,13 +205,85 @@ ipinfoLite({
167
205
});
168
206
```
169
207
208
+
### Core API
209
+
210
+
The library also supports the
211
+
[Core API](https://ipinfo.io/developers/data-types#core-data), which provides
212
+
city-level geolocation with nested geo and AS objects. Authentication with your
213
+
token is required.
214
+
215
+
```typescript
216
+
const { ipinfoCore } =require('ipinfo-express')
217
+
218
+
ipinfoCore({
219
+
token: "<token>",
220
+
cache: <cache_class>,
221
+
timeout: 5000,
222
+
ipSelector: null
223
+
});
224
+
```
225
+
226
+
### Plus API
227
+
228
+
The library also supports the
229
+
[Plus API](https://ipinfo.io/developers/data-types#plus-data), which provides
230
+
enhanced data including mobile carrier info and privacy detection.
console.log(req.ipinfo_resproxy.service); // Bright Data
269
+
}
270
+
res.send(req.ipinfo_resproxy)
271
+
})
272
+
```
170
273
171
274
### Other Libraries
172
275
173
-
There are official IPinfo client libraries available for many languages including PHP, Go, Java, Ruby, and many popular frameworks such as Django, Rails, and Laravel. There are also many third-party libraries and integrations available for our API.
276
+
There are official IPinfo client libraries available for many languages
277
+
including PHP, Go, Java, Ruby, and many popular frameworks such as Django,
278
+
Rails, and Laravel. There are also many third-party libraries and integrations
279
+
available for our API.
174
280
175
281
### About IPinfo
176
282
177
-
Founded in 2013, IPinfo prides itself on being the most reliable, accurate, and in-depth source of IP address data available anywhere. We process terabytes of data to produce our custom IP geolocation, company, carrier, VPN detection, hosted domains, and IP type data sets. Our API handles over 20 billion requests a month for 100,000 businesses and developers.
283
+
Founded in 2013, IPinfo prides itself on being the most reliable, accurate, and
284
+
in-depth source of IP address data available anywhere. We process terabytes of
285
+
data to produce our custom IP geolocation, company, carrier, VPN detection,
286
+
hosted domains, and IP type data sets. Our API handles over 20 billion requests
0 commit comments