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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@faircite/nextjs

v1.0.7

Published

FairCite bot detection middleware for Next.js

Readme

@faircite/nextjs-middleware

Official Next.js middleware for FairCite bot detection and analytics. Provides intelligent request batching to efficiently track and analyze bot traffic at scale.

Features

  • 🚀 High Performance - Non-blocking middleware with intelligent batching
  • 📦 Smart Batching - Automatically batches requests for efficient processing
  • 🔄 Automatic Retry - Built-in retry logic with exponential backoff
  • 🎯 Zero Config - Works out of the box with sensible defaults
  • 📊 Real-time Analytics - Track bot traffic patterns in real-time
  • 🔒 Secure - API key authentication with server-side processing
  • 🌐 Edge Compatible - Works with Vercel Edge Runtime and Node.js

Installation

npm install @faircite/nextjs-middleware
# or
yarn add @faircite/nextjs-middleware
# or
pnpm add @faircite/nextjs-middleware

Quick Start

1. Create middleware file

Create middleware.ts in your project root:

import { fcMiddleware } from '@faircite/nextjs-middleware';

export const middleware = fcMiddleware({
  siteId: 'pub_xxxxx',  // Your FairCite site ID
  apiKey: 'fc_xxxxx'    // Your FairCite API key
});

export const config = {
  matcher: '/((?!_next/static|_next/image|favicon.ico).*)',
};

2. Set environment variables (recommended)

Instead of hardcoding credentials, use environment variables:

# .env.local
FC_SITE_ID=pub_xxxxx
FC_API_KEY=fc_xxxxx

Then simplify your middleware:

import { fcMiddleware } from '@faircite/nextjs-middleware';

export const middleware = fcMiddleware();

export const config = {
  matcher: '/((?!_next/static|_next/image|favicon.ico).*)',
};

Configuration Options

fcMiddleware({
  // Required (if not using env vars)
  siteId?: string;        // Your FairCite site ID
  apiKey?: string;        // Your FairCite API key
  
  // Optional
  edgeUrl?: string;       // Custom edge worker URL (default: https://edge.faircite.com/v1/analyze)
  enabled?: boolean;      // Enable/disable middleware (default: true)
  batchSize?: number;     // Batch size threshold (default: 10)
  flushInterval?: number; // Flush interval in ms (default: 1000)
  debug?: boolean;        // Enable debug logging (default: false)
})

Environment Variables

All configuration options can be set via environment variables:

| Variable | Description | Default | |----------|-------------|---------| | FC_SITE_ID | Your FairCite site ID | - | | FC_API_KEY | Your FairCite API key | - | | FC_EDGE_URL | Custom edge worker URL | https://edge.faircite.com/v1/analyze | | FC_ENABLED | Enable/disable middleware | true | | FC_BATCH_SIZE | Number of requests to batch | 10 | | FC_FLUSH_INTERVAL | Batch flush interval (ms) | 1000 | | FC_DEBUG | Enable debug logging | false |

Performance

  • Minimal Overhead: < 1ms added to request processing
  • Non-blocking: Async processing doesn't delay responses
  • Memory Efficient: Automatic cleanup and size limits
  • Network Optimized: Batching reduces API calls by 10-100x

Compatibility

  • Next.js 13.0+ (App Router)
  • Next.js 12.2+ (Middleware support)
  • Node.js 16.8+
  • Vercel Edge Runtime
  • Self-hosted deployments

TypeScript

Full TypeScript support with exported types:

import type { FairCiteConfig, Detection } from '@faircite/nextjs-middleware';

Security

  • API keys are never exposed to the client
  • All processing happens server-side
  • Automatic sanitization of collected data
  • No personally identifiable information (PII) collected

Support

License

MIT © FairCite


Built with ❤️ by the FairCite team