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

@brahma-dev/abuseipdb-middleware

v1.1.1

Published

Universal middleware for reporting malicious IPs to AbuseIPDB. Supports Elysia, Express, Koa, Fastify, and Hono.

Readme

AbuseIPDB Middleware

A universal middleware for reporting malicious IP addresses to AbuseIPDB. Works with Elysia, Express, Koa, Fastify, and Hono.

Installation

npm install @brahma-dev/abuseipdb-middleware

Features

  • Universal: Works with all major Node.js/Bun frameworks.
  • Manual Reporting: Exposes a report function to manually flag IPs for any reason.
  • Configurable: Customize suspicious paths and report categories.
  • Efficient: Caches reported IPs to avoid duplicate API calls.
  • Lightweight: Minimal dependencies.

Usage

First, get your API key from the AbuseIPDB dashboard.

The middleware initializer returns an object containing the middleware itself and a report function for manual use.

Express

import express from 'express';
import { abuseIPDBExpress } from ' @brahma-dev/abuseipdb-middleware';

const app = express();
const { middleware, report } = abuseIPDBExpress({ apiKey: 'YOUR_API_KEY' });

app.use(middleware);
// ... your routes

Koa

import Koa from 'koa';
import { abuseIPDBKoa } from '@brahma-dev/abuseipdb-middleware';

const app = new Koa();
const { middleware, report } = abuseIPDBKoa({ apiKey: 'YOUR_API_KEY' });

app.use(middleware);
// ... your routes

Fastify

Fastify is slightly different. The report function is attached to the fastify instance via a decorator as app.abuseipdb.report.

import fastify from 'fastify';
import { abuseIPDBFastify } from '@brahma-dev/abuseipdb-middleware';

const app = fastify();
app.register(abuseIPDBFastify, { apiKey: 'YOUR_API_KEY' });
// ... your routes

Hono

import { Hono } from 'hono';
import { abuseIPDBHono } from '@brahma-dev/abuseipdb-middleware';

const app = new Hono();
const { middleware, report } = abuseIPDBHono({ apiKey: 'YOUR_API_KEY' });

app.use('*', middleware);
// ... your routes

Elysia

For Elysia, it's recommended to also use the elysia-ip plugin to ensure the IP address is correctly identified.

bun add elysia-ip
import { Elysia } from 'elysia';
import { ip } from 'elysia-ip';
import { abuseIPDBElysia } from '@brahma-dev/abuseipdb-middleware';

const { middleware, report } = abuseIPDBElysia({ apiKey: 'YOUR_API_KEY' });

new Elysia()
  .use(ip()) // Recommended: makes `context.ip` available
  .use(middleware)
  .get('/', () => 'Hello Elysia')
  .listen(3000);```

## Manual Reporting

The exposed `report` function allows you to report IPs for application-specific reasons, such as failed login attempts, spam, or unusual API usage.

The function has the following signature:
`report(ip: string, comment: string, categories?: string): Promise<void>`

- **`ip`**: The IP address to report.
- **`comment`**: A description of the malicious activity.
- **`categories`** (optional): A comma-separated string of AbuseIPDB category codes. Defaults to the one in the options.

### Example: Reporting a Failed Login (Express)
```typescript
app.post('/login', (req, res) => {
  const { username, password } = req.body;
  const {loginSuccess, attemptCount } = authenticate(username, password); // Your auth logic

  if (!loginSuccess ) {
    if(attemptCount>10) {
      // Report the IP for a failed login (Category 18: Brute-Force)
      report(req.ip, `Failed login attempt for user "${username}"`, '18');
    }
    return res.status(401).send('Authentication failed.');
  }
  
  res.send('Logged in!');
});

Example: Manual Reporting (Fastify)

app.post('/comment', (req, reply) => {
    const isSpam = detectSpam(req.body); // Your spam detection logic
    if (isSpam) {
        // Use the decorator to report the IP
        app.abuseipdb.report(req.ip, 'User submitted spam comment.', '14');
        return reply.status(400).send('Spam detected.');
    }
    //...
});

Configuration Options

You can pass an options object to the middleware factory:

interface AbuseIPDBOptions {
  apiKey: string; // Required
  paths?: string[]; // Replace default suspicious paths
  additionalPaths?: string[]; // Add to default suspicious paths
  categories?: string; // Comma-separated AbuseIPDB category codes (defaults to "21")
  cacheTTL?: number; // How long to cache IPs in ms (defaults to 1 hour)
}