nest-geoip2
v1.2.2
Published
MaxMind GeoIP2 module for Nest framework.
Downloads
25
Readme
nest-geoip2
MaxMind GeoIP2 module for Nest framework.
Install
npm i nest-geoip2 @maxmind/geoip2-node
// or
yarn add nest-geoip2 @maxmind/geoip2-node
Usage
// app.module.ts
import { Module } from "@nestjs/common";
import { GeoIP2Module } from "nest-geoip2";
import { join } from "path";
import { AppController } from "./app.controller.ts";
@Module({
imports: [
GeoIP2Module.registerRender(join(process.cwd(), "GeoLite2-City.mmdb")),
],
controllers: [AppController],
})
export class AppModule {}
// app.controller.ts
import { Controller, Get, Ip } from "@nestjs/common";
import { ReaderModel } from "nest-geoip2";
@Controller()
export class AppController {
public constructor(private readonly readerModel: ReaderModel) {
return this;
}
@Get("ip")
public async ip(@Ip() ip: string) {
return this.readerModel.city(ip);
}
}
Other
How to get GeoIP2/GeoLite2 database?
https://dev.maxmind.com/geoip/geoipupdate/#Direct_Downloads
https://www.maxmind.com/en/accounts/current/geoip/downloads