npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@gagandeep023/api-gateway

v0.6.0

Published

Type-safe Express API gateway with IP-based rate limiting, analytics, and React dashboard

Downloads

1,012

Readme

@gagandeep023/api-gateway

Type-safe Express API gateway with IP-based rate limiting, analytics, and a real-time React dashboard.

npm version license

Features

  • Three rate limiting algorithms: Token Bucket, Sliding Window, Fixed Window
  • IP-based rate limiting and session tracking
  • API key authentication with configurable tiers
  • IP allowlist/blocklist filtering
  • Real-time analytics with circular buffer (10k entries)
  • SSE-powered React dashboard with charts
  • Zero external dependencies beyond Express and React
  • Full TypeScript support

Installation

npm install @gagandeep023/api-gateway

Quick Start: Backend

import express from 'express';
import { createGatewayMiddleware, createGatewayRoutes } from '@gagandeep023/api-gateway/backend';

const app = express();
app.use(express.json());

// Create gateway with default config
const gateway = createGatewayMiddleware();

// Mount management routes (bypasses rate limiting)
app.use('/api/gateway', createGatewayRoutes({
  rateLimiterService: gateway.rateLimiterService,
  analyticsService: gateway.analyticsService,
  config: gateway.config,
}));

// Apply rate limiting to all other routes
app.use('/api', gateway.middleware);

// Your routes go after the middleware
app.get('/api/hello', (req, res) => {
  res.json({ message: 'Hello, world!' });
});

app.listen(3001);

Quick Start: Frontend Dashboard

import { GatewayDashboard } from '@gagandeep023/api-gateway/frontend';
import '@gagandeep023/api-gateway/frontend/styles.css';

function App() {
  return <GatewayDashboard apiBaseUrl="http://localhost:3001/api" />;
}

Custom Configuration

import { createGatewayMiddleware } from '@gagandeep023/api-gateway/backend';

const gateway = createGatewayMiddleware({
  rateLimits: {
    tiers: {
      free: { algorithm: 'tokenBucket', maxRequests: 100, windowMs: 60000, refillRate: 10 },
      pro: { algorithm: 'slidingWindow', maxRequests: 1000, windowMs: 60000 },
      unlimited: { algorithm: 'none' },
    },
    defaultTier: 'free',
    globalLimit: { maxRequests: 10000, windowMs: 60000 },
  },
  ipRules: {
    allowlist: [],
    blocklist: ['10.0.0.1'],
    mode: 'blocklist',
  },
  apiKeys: {
    keys: [
      {
        id: 'key_001',
        key: 'my_secret_key',
        name: 'My App',
        tier: 'pro',
        createdAt: new Date().toISOString(),
        active: true,
      },
    ],
  },
});

API Reference

Backend

createGatewayMiddleware(config?)

Creates the full middleware chain and returns service instances.

Parameters:

| Parameter | Type | Required | Description | |-----------|------|----------|-------------| | config.rateLimits | RateLimitConfig | No | Rate limit tiers and global limit | | config.ipRules | IpRules | No | IP allowlist/blocklist rules | | config.apiKeys | ApiKeysConfig | No | API keys and tiers |

Returns: GatewayInstances

| Property | Type | Description | |----------|------|-------------| | middleware | Router | Express router with full middleware chain | | rateLimiterService | RateLimiterService | Rate limiter instance | | analyticsService | AnalyticsService | Analytics instance | | config | GatewayMiddlewareConfig | Resolved config |

createGatewayRoutes(options)

Creates Express routes for gateway management (analytics, config, key CRUD, logs).

Individual Middleware

  • createApiKeyAuth(getKeys) - API key authentication
  • createIpFilter(getRules) - IP filtering
  • createRateLimiter(service) - Rate limiting
  • createRequestLogger(analytics) - Request logging

Frontend

<GatewayDashboard apiBaseUrl={string} />

React component displaying real-time gateway analytics.

Props:

| Prop | Type | Description | |------|------|-------------| | apiBaseUrl | string | Base URL of the backend API (e.g. http://localhost:3001/api) |

IP-Based Tracking

All rate limiting is enforced per IP address. The dashboard shows:

  • Active IPs: Unique IP addresses seen in the last 5 minutes
  • Active Key Sessions: Unique (IP + API key) pairs in the last 5 minutes

Theming the Dashboard

Override CSS custom properties to match your theme:

.gw-dashboard {
  --gw-bg-card: #1a1a2e;
  --gw-accent: #00d4ff;
  --gw-text-primary: #ffffff;
}

TypeScript

Full TypeScript support with exported types:

import type {
  RateLimitConfig,
  GatewayAnalytics,
  GatewayConfig,
  RequestLog,
  ApiKey,
  IpRules,
  TierConfig,
} from '@gagandeep023/api-gateway/types';

License

MIT