ip-details-fetcher
v1.0.0
Published
Best NPM package to fetch IP details
Downloads
15
Maintainers
Readme
Best NPM package to fetch IP details using the ipinfo.io API.
Installation
npm install ip-details-fetcher
Usage
import { getIPDetails } from 'ip-details-fetcher';
const token = 'YOUR_TOKEN_HERE'; // Replace with your actual token
getIPDetails(token).then(ipDetails => {
console.log('IP Details:', ipDetails);
}).catch(error => {
console.error('Error fetching IP details:', error);
});
Getting Your API Token
To use this package, you need an API token from ipinfo.io. Follow these steps to get your token:
- Visit the ipinfo.io website.
- Sign up for an account or log in if you already have one.
- Once logged in, you will find your API token on the account home page.
- Copy the token and replace
'YOUR_TOKEN_HERE'
in the usage example above with your actual token.
Example
import React, { useEffect, useState } from 'react';
import { getIPDetails, IPDetails } from 'ip-details-fetcher';
const App = () => {
const [ipDetails, setIpDetails] = useState<IPDetails | null>(null);
const token = 'YOUR_TOKEN_HERE'; // Replace with your actual token
useEffect(() => {
getIPDetails(token).then(setIpDetails).catch(error => console.error('Error fetching IP details:', error));
}, [token]);
if (!ipDetails) return <div>Loading...</div>;
return (
<div>
<h1>Your IP Details</h1>
<p><strong>IP:</strong> {ipDetails.ip}</p>
<p><strong>City:</strong> {ipDetails.city}</p>
<p><strong>Region:</strong> {ipDetails.region}</p>
<p><strong>Country:</strong> {ipDetails.country}</p>
<p><strong>Latitude and Longitude:</strong> {ipDetails.latitude}, {ipDetails.longitude}</p>
<p><strong>Timezone:</strong> {ipDetails.timezone}</p>
<p><strong>ISP:</strong> {ipDetails.org}</p>
</div>
);
};
export default App;
License
This package is licensed under the ISC License.
This README.md
provides clear instructions on how to install, use the package, and obtain the necessary API token from ipinfo.io.