# geo-lookup-api

- Can be used as a middleware / api route for popular frameworks like Next.JS, etc.

Example in Next.JS

Create a file in `/pages/api` directory, for e.g `/pages/api/geo.js`

```javascript
const { handler } = require("@renec-foundation/geo-lookup-api");

const api = async (req, res) => await handler(req, res);

export default api;
```

request `host/api/geo`

```json
{ "lang": "vi", "info": { "ip": "42.114.185.210" } }
```

Utility method:

```javascript
const { getCountry } = require("@renec-foundation/geo-lookup-api");

getCountry("ip_string");
```

Run test:

```shell
yarn test
```

Or you can test with a remote database

```shell
❯ GEO_DB_URL=https://git.io/GeoLite2-Country.mmdb yarn test
```

```Link download
https://github.com/P3TERX/GeoLite.mmdb?tab=readme-ov-file
```
