Logo

TypeScript Library

The ipflare npm package offers a simple and efficient way to retrieve geolocation information for IP addresses using the IP Flare API.

Installation

1npm install ipflare

Usage

After installing the package, you can use it in your JavaScript or TypeScript projects to fetch geolocation data.

Initialize the Client

1// ipflare.ts
2
3import { IPFlare } from "ipflare";
4
5// Initialize with your API key (required)
6const geolocator = new IPFlare({
7 apiKey: 'YOUR_API_KEY',
8});

Examples

Once the client is initialized, you can use it to fetch geolocation data within your application. Below are some examples of how to use the client to retrieve geolocation information.

Single IP Lookup

The following example demonstrates how to use the client to fetch geolocation data for a single IP address.

1// Look up a single IP address
2const result = await geolocator.lookup("178.238.11.6");
3
4console.log(result);

Lookup with Additional Fields

To retrieve additional fields, pass an array of desired fields. Visit the Geolocation page for more information.

1// Look up with additional fields
2const resultWithFields = await geolocator.lookup("178.238.11.6", {
3 include: {
4 asn: true,
5 isp: true,
6 },
7});
8
9console.log(resultWithFields);

Bulk IP Lookup

The following example demonstrates how to use the client to fetch geolocation data for multiple IP addresses. Note the results may not correspond in order to the input list.

1// Look up multiple IP addresses
2const bulkResults = await geolocator.bulkLookup({
3 ips: ["178.238.11.6", "1.1.1.1"],
4 include: {
5 asn: true,
6 isp: true,
7 },
8 });
9
10 console.log(bulkResults);

TypeScript Types

The ipflare library provides the following types to ensure correct data handling:

1import {
2 IPFlare,
3 type BulkLookupOptions,
4 type BulkLookupResponse,
5 type IPGeolocationError,
6 type IPGeolocationOptions,
7 type IPGeolocationResponse,
8 type IPGeolocationSuccess,
9 type LookupOptions,
10} from "ipflare";