Skip to content

Latest commit

 

History

History
63 lines (50 loc) · 2.18 KB

README.md

File metadata and controls

63 lines (50 loc) · 2.18 KB

nest-geoip2

Build Status Coverage Status License Version Code Style: Prettier Commitizen friendly Semantic Release Dependabot

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