1.0.12 • Published 1 year ago

@akinolae/node-rate-limiter v1.0.12

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

@akinolae/node-rate-limiter

Description

The @akinolae/node-rate-limiter package provides an efficient and flexible solution for controlling the frequency of API requests or other operations. It helps developers prevent excessive usage, safeguard system resources, and ensure compliance with rate-limiting policies.

This package is particularly useful for managing API usage, protecting backend services from overload, and maintaining fair usage across users or clients.

npm i @akinolae/node-rate-limiter
yarn add @akinolae/node-rate-limiter

Usage

Documents are groups of pages connected through:

express.js

Usage with express.js node.js

import { requestLimitCore } from '@akinolae/node-rate-limiter';

const makeRequest = async (req: Request, res: Response) => {
  try {
    /***
     * Can make it a middleware for authenticated requests
     *
     */

    requestLimitCore({
      request: req,
      session_no: 6,
      ttl: 6 * 60 * 1000,
    });

    // auth calls go here
  } catch (e) {
    throw e;
  }
};

@nestJS

Usage with @nestJs and graphQL

import { requestLimitCore } from '@akinolae/node-rate-limiter';
import { ExecutionContext } from '@nestjs/common';

const makeRequest = async (context: ExecutionContext) => {
  try {
    /***
     * Can make it a middleware for authenticated requests i.e auth-guard
     *
     */

    requestLimitCore({
      request: context.getArgByIndex(2).req,
      session_no: 6,
      ttl: 6 * 60 * 1000,
    });

    // auth calls go here
  } catch (e) {
    throw e;
  }
};

Configuration

OptionTypeDescription
ttlnumbertime to live optional
session_nonumberThe number of times a request can be called optional
requestobjectThe request object that carries the metadata of an incoming request required
1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago