find-my-location
Version:
Find user location from their ip
55 lines (40 loc) • 897 B
Markdown
Find user location from their ip
Using npm:
```console
npm install find-my-location
```
or if you prefer using yarn:
```console
yarn add find-my-location
```
```js
import fml from "find-my-location";
// or if you don't use ES6 import:
// const fml = require("find-my-location").default;
const dummy = async () => {
const location = await fml("112.69.120.199");
console.log(location);
};
dummy();
/*
The response will be:
{
ip: "112.69.120.199",
country_code: "JP",
country_name: "Japan",
region_code: "27",
region_name: "Ōsaka",
city: "Osaka",
zip_code: "543-0062",
time_zone: "Asia/Tokyo",
latitude: 34.6851,
longitude: 135.5136,
metro_code: 0
}
*/
```
This library uses [freegeoapi](https://freegeoip.app/) API to function, we are allowed up to 15,000 requests per hour.