### Install node-iplocate using Yarn, npm, or pnpm Source: https://github.com/iplocate/node-iplocate/blob/master/README.md Installs the node-iplocate package for use in your Node.js project. This is the first step to integrate IP geolocation and threat detection capabilities. ```bash yarn add node-iplocate # or npm install node-iplocate # or pnpm add node-iplocate ``` -------------------------------- ### Quick start: Lookup an IP address with node-iplocate Source: https://github.com/iplocate/node-iplocate/blob/master/README.md Demonstrates the basic usage of the IPLocate client to look up an IP address. It shows how to initialize the client with an API key and retrieve geolocation and privacy data. ```javascript import IPLocate from 'node-iplocate'; // or: const IPLocate = require('node-iplocate').default; // Create a client with your API key // Get your free API key from https://iplocate.io/signup const client = new IPLocate('your-api-key'); // Look up an IP address const result = await client.lookup('8.8.8.8'); console.log(`IP: ${result.ip}`); if (result.country) { console.log(`Country: ${result.country}`); } if (result.city) { console.log(`City: ${result.city}`); } // Check privacy flags console.log(`Is VPN: ${result.privacy.is_vpn}`); console.log(`Is Proxy: ${result.privacy.is_proxy}`); ``` -------------------------------- ### IP address geolocation lookup example Source: https://github.com/iplocate/node-iplocate/blob/master/README.md A comprehensive example of performing an IP address lookup and extracting both country and coordinate information. It demonstrates accessing nested properties like latitude and longitude. ```typescript import IPLocate from 'node-iplocate'; const client = new IPLocate('your-api-key'); const result = await client.lookup('203.0.113.1'); console.log(`Country: ${result.country} (${result.country_code})`); if (result.latitude && result.longitude) { console.log(`Coordinates: ${result.latitude}, ${result.longitude}`); } ``` -------------------------------- ### IPLocate Error Handling Example (TypeScript) Source: https://github.com/iplocate/node-iplocate/blob/master/README.md Provides a comprehensive example of how to handle errors when using the IPLocate client. It shows how to catch specific error classes like InvalidIPError, AuthenticationError, NotFoundError, RateLimitError, and general APIError, along with their common causes and HTTP status codes. ```typescript import IPLocate, InvalidIPError, AuthenticationError, NotFoundError, RateLimitError, APIError from 'node-iplocate'; const client = new IPLocate('your-api-key'); try { const result = await client.lookup('8.8.8.8'); console.log(result); } catch (error) { if (error instanceof InvalidIPError) { console.log('Invalid IP address format'); } else if (error instanceof AuthenticationError) { console.log('Invalid API key'); } else if (error instanceof NotFoundError) { console.log('IP address not found'); } else if (error instanceof RateLimitError) { console.log('Rate limit exceeded'); } else if (error instanceof APIError) { console.log(`API error (${error.statusCode}): ${error.message}`); } else { console.log('Unknown error:', error); } } ``` -------------------------------- ### Development Commands (Bash) Source: https://github.com/iplocate/node-iplocate/blob/master/README.md A collection of essential bash commands for managing the node-iplocate project. This includes installing dependencies, running tests (with and without coverage), building the library, performing type checking, and linting the code. ```bash yarn install ``` ```bash yarn test ``` ```bash yarn test:coverage ``` ```bash yarn build ``` ```bash yarn type-check ``` ```bash yarn lint ``` ```bash yarn lint:fix ``` -------------------------------- ### Get currency code for a country by IP address Source: https://github.com/iplocate/node-iplocate/blob/master/README.md Extracts the currency code associated with the country identified by an IP address. This can be useful for e-commerce or localized services. ```typescript const result = await client.lookup('203.0.113.1'); console.log(`Currency: ${result.currency_code}`); ``` -------------------------------- ### Get calling code for a country by IP address Source: https://github.com/iplocate/node-iplocate/blob/master/README.md Retrieves the international direct dialing (IDD) or calling code for the country associated with an IP address. This is helpful for telephony or communication features. ```typescript const result = await client.lookup('203.0.113.1'); console.log(`Calling code: +${result.calling_code}`); ``` -------------------------------- ### Get country details for an IP address Source: https://github.com/iplocate/node-iplocate/blob/master/README.md Fetches the country name and its corresponding two-letter country code for a given IP address. This snippet focuses on extracting specific country-related information from the lookup result. ```typescript const result = await client.lookup('203.0.113.1'); console.log(`Country: ${result.country} (${result.country_code})`); ``` -------------------------------- ### Authenticate IPLocate client with API key Source: https://github.com/iplocate/node-iplocate/blob/master/README.md Shows how to initialize the IPLocate client by providing your API key during instantiation. The API key is required for making requests to the IPLocate.io service. ```typescript const client = new IPLocate('your-api-key'); ``` -------------------------------- ### Importing IPLocate Types (TypeScript) Source: https://github.com/iplocate/node-iplocate/blob/master/README.md Demonstrates how to import the main IPLocate class and various related types and interfaces from the node-iplocate library into your TypeScript project for type safety and autocompletion. ```typescript import IPLocate, { LookupResponse, ASN, Privacy, Company, Hosting, Abuse, IPLocateOptions } from 'node-iplocate'; ``` -------------------------------- ### Configure custom timeout and HTTP options Source: https://github.com/iplocate/node-iplocate/blob/master/README.md Shows how to customize the client's behavior by setting a custom request timeout and providing custom HTTP client options, such as headers or a custom base URL for enterprise use. ```typescript import IPLocate from 'node-iplocate'; // Custom timeout and HTTP options const client = new IPLocate('your-api-key', { timeout: 60000, // 60 seconds baseUrl: 'https://custom-endpoint.com/api', // For enterprise customers httpClientOptions: { headers: { 'Custom-Header': 'value' } } }); ``` -------------------------------- ### LookupResponse Interface Definition (TypeScript) Source: https://github.com/iplocate/node-iplocate/blob/master/README.md Defines the structure of the data returned by the IP geolocation service. It includes fields for IP address, geographical location, network details, and associated metadata. ```typescript interface LookupResponse { ip: string; country?: string; country_code?: string; is_eu: boolean; city?: string; continent?: string; latitude?: number; longitude?: number; time_zone?: string; postal_code?: string; subdivision?: string; currency_code?: string; calling_code?: string; network?: string; asn?: ASN; privacy: Privacy; company?: Company; hosting?: Hosting; abuse?: Abuse; } ``` -------------------------------- ### Retrieve ASN and network information Source: https://github.com/iplocate/node-iplocate/blob/master/README.md Fetches Autonomous System Number (ASN) details, including the ASN number, Internet Service Provider (ISP) name, and network route information for a given IP address. ```typescript const result = await client.lookup('8.8.8.8'); if (result.asn) { console.log(`ASN: ${result.asn.asn}`); console.log(`ISP: ${result.asn.name}`); console.log(`Network: ${result.asn.route}`); } ``` -------------------------------- ### Check for VPN, Proxy, or Tor usage Source: https://github.com/iplocate/node-iplocate/blob/master/README.md Demonstrates how to check privacy-related flags returned by the API, specifically identifying if an IP address is associated with a VPN, proxy, or the Tor network. ```typescript const result = await client.lookup('192.0.2.1'); if (result.privacy.is_vpn) { console.log('This IP is using a VPN'); } if (result.privacy.is_proxy) { console.log('This IP is using a proxy'); } if (result.privacy.is_tor) { console.log('This IP is using Tor'); } ``` -------------------------------- ### Lookup your own IP address information Source: https://github.com/iplocate/node-iplocate/blob/master/README.md Retrieves geolocation and threat intelligence data for the IP address from which the request is made. This is useful for identifying the location and characteristics of the current user or server. ```typescript // Look up your own IP address (no IP parameter) const result = await client.lookupSelf(); console.log(`Your IP: ${result.ip}`); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.