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

@foxen/core

v1.4.0

Published

Core runtime for Next.js App Router compatibility - NextRequest, NextResponse, cookies, headers

Readme

@foxen/core

Core runtime for Next.js App Router compatibility. Provides 1:1 compatible implementations of Next.js server APIs for use with Elysia and Bun.

Installation

bun add @foxen/core

Usage

NextRequest

import { NextRequest } from "@foxen/core";

export async function GET(request: NextRequest) {
    // URL and path info
    const pathname = request.nextUrl.pathname;
    const searchParams = request.nextUrl.searchParams;

    // Headers
    const userAgent = request.headers.get("user-agent");

    // Cookies
    const token = request.cookies.get("token");

    // Geo and IP (when available)
    const ip = request.ip;
    const geo = request.geo;

    return NextResponse.json({ pathname, userAgent });
}

NextResponse

import { NextResponse } from "@foxen/core";

// JSON response
return NextResponse.json({ message: "Hello" });

// With status code
return NextResponse.json({ error: "Not found" }, { status: 404 });

// Redirect
return NextResponse.redirect(new URL("/login", request.url));

// Rewrite (transparent)
return NextResponse.rewrite(new URL("/api/v2/users", request.url));

// Continue to next handler (middleware)
return NextResponse.next();

// With headers
const response = NextResponse.json({ data: "..." });
response.headers.set("X-Custom-Header", "value");
return response;

// With cookies
const response = NextResponse.json({ success: true });
response.cookies.set("session", "abc123", { httpOnly: true });
return response;

Cookies

import { NextRequest, NextResponse } from "@foxen/core";

export async function POST(request: NextRequest) {
    // Read cookies from request
    const sessionId = request.cookies.get("session")?.value;
    const allCookies = request.cookies.getAll();

    // Create response with cookies
    const response = NextResponse.json({ success: true });

    // Set cookie
    response.cookies.set("token", "abc123", {
        httpOnly: true,
        secure: true,
        sameSite: "strict",
        maxAge: 60 * 60 * 24, // 1 day
    });

    // Delete cookie
    response.cookies.delete("old-cookie");

    return response;
}

Error Handling

import { FoxenError, ConfigError, RouteError, formatError } from "@foxen/core";

// Throw specific error types
throw new ConfigError("Config file not found", "CONFIG_NOT_FOUND", {
    path: "./foxen.config.ts",
});

throw new RouteError("No handlers exported", "ROUTE_NO_HANDLERS", {
    filePath: "./src/app/api/users/route.ts",
});

// Format errors for CLI display
try {
    // ... some operation
} catch (error) {
    console.error(formatError(error));
    // Output includes error message, code, phase, details, and suggestion
}

API Reference

NextRequest

| Property/Method | Description | |-----------------|-------------| | nextUrl | NextURL instance with pathname, searchParams, etc. | | cookies | RequestCookies instance | | headers | Standard Headers object | | method | HTTP method (GET, POST, etc.) | | ip | Client IP address (when available) | | geo | Geolocation data (when available) |

NextResponse

| Method | Description | |--------|-------------| | NextResponse.json(body, init?) | Create JSON response | | NextResponse.redirect(url, status?) | Create redirect response | | NextResponse.rewrite(url) | Create rewrite response | | NextResponse.next(init?) | Continue to next handler | | response.cookies | ResponseCookies instance | | response.headers | Standard Headers object |

Error Types

| Error Class | Use Case | |-------------|----------| | FoxenError | Base error class | | ConfigError | Configuration issues | | RouteError | Route loading issues | | MiddlewareError | Middleware issues | | SchemaError | Schema validation issues | | CompileError | Compilation issues | | RuntimeError | Runtime issues |

Compatibility

This package aims for 100% API compatibility with Next.js server components:

  • NextRequest
  • NextResponse
  • NextURL
  • RequestCookies
  • ResponseCookies
  • cookies() (via request.cookies)
  • headers() (via request.headers)

License

MIT