Giter Site home page Giter Site logo

maticapuano / nest-request-ip Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 15 KB

Nest.js module that simplifies the process of retrieving important information from incoming HTTP requests

Home Page: https://www.npmjs.com/package/nest-request-ip

License: MIT License

TypeScript 100.00%
express middleware nestjs

nest-request-ip's Introduction

Nest Request IP

Nest Request IP is a convenient Nest.js module that allows you to effortlessly retrieve information from HTTP requests, including client IP addresses, user agents, browsers, and operating systems. With this module, you can enhance your Nest.js application's functionality by gaining insights into the characteristics of incoming requests.

Features

  • Get IP from HTTP requests
  • Discover agent, browser, device, OS, etc.
  • Get city, country, region, timezone from IP

Installation

npm install nest-request-ip --save

Usage

app.module.ts

import { Module } from "@nestjs/common";
import { RequestIpModule } from "nest-request-ip";
import { AppController } from "./app.controller";
import { AppService } from "./app.service";

@Module({
  imports: [
    RequestIpModule.forRoot({
      localIpAddress: "76.76.21.123", // this ip is used when the request is local
    }),
  ],
  controllers: [AppController],
})
export class AppModule {}

app.controller.ts

import { Controller, Get, Req } from "@nestjs/common";
import { Request } from "express";
import {
  GetClientIp,
  GetClientAgent,
  GetClientBrowser,
  GetClientSystem,
} from "nest-request-ip";

@Controller()
export class AppController {
  @Get()
  getHello(@GetClientIp() ip: ClientInfo) {
    return ip;
  }

  @Get("agent")
  getAgent(@GetClientAgent() agent: string) {
    return agent;
  }

  @Get("browser")
  getBrowser(@GetClientBrowser() browser: string) {
    return browser;
  }

  @Get("system")
  getSystem(@GetClientSystem() system: string) {
    return system;
  }
}

License

MIT licensed.

nest-request-ip's People

Contributors

maticapuano avatar

Watchers

 avatar

nest-request-ip's Issues

Huge memory drain

Hi community and developer,

I've added this as a module. And my memory heap size increased up to 173mb from 24.6mb. Railway memory metrics increased up to 213mb from 66mb.

Can we fix this? It's a great tool but takes way more memory.

Here's the screenhots:

  1. Snapshot 1 is included version of nest-request-ip module. Other snapshots is after removing it
    image

  2. Railway metrics view. As you can see it's 213mb. Before it was 60-70mb
    image

Thank you for your attention

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.