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

foxn

v1.5.1

Published

Foxen - Next.js API Routes → Elysia Migration Framework

Downloads

466

Readme

foxen

Meta package that re-exports everything from all Foxen packages, providing a single import for the complete framework.

Installation

bun add foxn

This installs all Foxen packages:

  • @foxen/core - NextRequest, NextResponse, cookies
  • @foxen/helpers - userAgent, geo, IP detection
  • @foxen/config - Configuration and next.config.ts support
  • @foxen/middleware - middleware.ts support
  • @foxen/adapter - Runtime Elysia plugin
  • @foxen/cli - Command-line tools

Quick Start

import { Elysia } from "elysia";
import { NextRequest, NextResponse, appRouter, defineConfig } from "foxn";

// Create server with routes
const app = new Elysia()
    .use(await appRouter({ apiDir: "./src/app/api" }))
    .listen(3000);

What's Included

Core Runtime

import {
    // Request/Response
    NextRequest,
    NextResponse,
    NextURL,

    // Cookies
    RequestCookies,
    ResponseCookies,

    // Types
    type HttpMethod,
    type NextRouteHandler,
} from "foxn";

Helpers

import {
    userAgent,
    type UserAgent,
} from "foxn";

Navigation Helpers

import {
    headers,
    cookies,
    draftMode,
    redirect,
    notFound,
    foxenInterruptHandler,
} from "foxn";

export async function GET() {
    const hdrs = await headers();
    const jar = await cookies();
    if (!jar.get("session")) {
        redirect("/login");
    }
    return Response.json({ forwardFor: hdrs.get("x-forwarded-for") });
}

// Add interrupt middleware if you are building your own Elysia app
const app = new Elysia().use(foxenInterruptHandler());

Need the plugin without the rest of foxn? Import foxenInterruptHandler directly from @foxen/middleware.

Configuration

import {
    // Config loading
    loadFoxenConfig,
    loadNextConfig,
    defineConfig,
    defineFoxenConfig,

    // Path matching
    matchPath,
    matchConditions,
    applyParams,

    // Request processing
    processRedirects,
    processRewrites,
    processHeaders,
} from "foxn";

Adapter

import {
    appRouter,
    createApp,
    scanDirectory,
    convertPathToElysia,
    type AppRouterConfig,
} from "foxn";

Middleware

import {
    loadMiddleware,
    executeMiddleware,
    shouldRunMiddleware,
    NextFetchEvent,
} from "foxn";

CLI Configuration

import { defineConfig, type Config } from "foxn";

// foxen.config.ts
export default defineConfig({
    routesDir: "./src/app/api",
    outputDir: "./src/generated",
    basePath: "/api",
});

TypeBox (from Elysia)

import { t } from "foxn";

// Use for schemas
const UserSchema = t.Object({
    id: t.String(),
    name: t.String(),
    email: t.String({ format: "email" }),
});

Usage Example

// server.ts
import { Elysia } from "elysia";
import { appRouter, NextRequest, NextResponse } from "foxn";

const app = new Elysia()
    .get("/health", () => ({ status: "ok" }))
    .use(
        await appRouter({
            apiDir: "./src/app/api",
            middlewarePath: "./middleware.ts",
            nextConfigPath: "./next.config.ts",
            features: {
                redirects: true,
                rewrites: true,
                headers: true,
                middleware: true,
            },
        }),
    )
    .listen(3000);
// src/app/api/users/route.ts
import { NextRequest, NextResponse } from "foxn";

export async function GET(request: NextRequest) {
    const users = await getUsers();
    return NextResponse.json({ users });
}

export async function POST(request: NextRequest) {
    const body = await request.json();
    const user = await createUser(body);
    return NextResponse.json(user, { status: 201 });
}
// middleware.ts
import { NextRequest, NextResponse } from "foxn";

export function middleware(request: NextRequest) {
    const token = request.cookies.get("token");

    if (!token && request.nextUrl.pathname.startsWith("/api/protected")) {
        return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
    }

    return NextResponse.next();
}

export const config = {
    matcher: "/api/:path*",
};

CLI Commands

# Initialize configuration
bunx foxn init

# Generate routes
bunx foxn generate

# Start dev server
bunx foxn dev

# Migrate Next.js project
bunx foxn migrate ./my-app

When to Use

Use foxen when:

  • You want the simplest setup
  • You need all features
  • You're building a new project

Use individual packages when:

  • You only need specific functionality
  • You want minimal bundle size
  • You're integrating with existing code

Package Structure

foxen (meta package)
├── @foxen/core      → NextRequest, NextResponse
├── @foxen/helpers   → userAgent, geo, IP
├── @foxen/config    → Configuration, next.config.ts
├── @foxen/middleware → middleware.ts support
├── @foxen/adapter   → Elysia runtime plugin
└── @foxen/cli       → CLI tools

License

MIT