nest-geoip2
TypeScript icon, indicating that this package has built-in type declarations

1.2.2 • Public • Published

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

Package Sidebar

Install

npm i nest-geoip2

Weekly Downloads

16

Version

1.2.2

License

MIT

Unpacked Size

35.1 kB

Total Files

17

Last publish

Collaborators

  • xudong