Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/svtslv/nestjs-geoip2
Maxmind GeoIP2 module for Nest
https://github.com/svtslv/nestjs-geoip2
geoip2 maxmind nest nestjs
Last synced: 3 months ago
JSON representation
Maxmind GeoIP2 module for Nest
- Host: GitHub
- URL: https://github.com/svtslv/nestjs-geoip2
- Owner: svtslv
- Created: 2020-02-29T00:36:20.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-17T20:57:58.000Z (over 1 year ago)
- Last Synced: 2024-03-18T06:03:33.827Z (10 months ago)
- Topics: geoip2, maxmind, nest, nestjs
- Language: TypeScript
- Homepage:
- Size: 1.5 MB
- Stars: 5
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NestJS GeoIP2
## Table of Contents
- [Description](#description)
- [Installation](#installation)
- [Examples](#examples)
- [License](#license)## Description
Integrates MaxMind GeoIP2 with Nest## Installation
```sh
npm install nestjs-geoip2 @maxmind/geoip2-node
```You can also use the interactive CLI
```sh
npx nestjs-modules
```## Examples
```sh
npx geoip2-cli --download --licenseKey=MAXMIND_LICENSE_KEY
```### GeoIP2Module.forRoot(options, connection?)
```ts
import { Module } from '@nestjs/common';
import { GeoIP2Module } from 'nestjs-geoip2';
import { AppController } from './app.controller';
import { join } from 'path';@Module({
imports: [
GeoIP2Module.forRoot({
config: {
file: join(process.cwd(), 'geoip2-cli', 'GeoLite2-City.mmdb'),
},
}),
],
controllers: [AppController],
})
export class AppModule {}
```### GeoIP2Module.forRootAsync(options, connection?)
```ts
import { Module } from '@nestjs/common';
import { GeoIP2Module } from 'nestjs-geoip2';
import { AppController } from './app.controller';
import { join } from 'path';@Module({
imports: [
GeoIP2Module.forRootAsync({
useFactory: () => ({
config: {
file: join(process.cwd(), 'geoip2-cli', 'GeoLite2-City.mmdb'),
},
}),
}),
],
controllers: [AppController],
})
export class AppModule {}
```### InjectGeoIP2(connection?)
```ts
import { Controller, Get, } from '@nestjs/common';
import { InjectGeoIP2, GeoIP2 } from 'nestjs-geoip2';@Controller()
export class AppController {
constructor(
@InjectGeoIP2() private readonly geoIP2: GeoIP2,
) {}@Get()
async getHello() {
return await this.geoIP2.city('8.8.8.8');
}
}
```## License
MIT