API Reference
Complete reference for all NextRush packages — types, methods, and configuration options.
Every NextRush package is documented with full type signatures, method descriptions, and usage examples. Install only what you need.
Package Architecture
Loading diagram...
Quick Start
For most projects, install the meta package:
$ pnpm add nextrush
This gives you:
createApp()— Application factorycreateRouter()— Router factorylisten()— Start Node.js server- HTTP error classes
- Essential types
import { createApp, createRouter, listen } from 'nextrush';
const app = createApp();
const router = createRouter();
router.get('/', (ctx) => ctx.json({ hello: 'world' }));
app.route('/', router);
await listen(app, 3000);Package Categories
Core Foundation
The foundational packages that everything else builds on.
| Package | Purpose | Install Separately? |
|---|---|---|
nextrush | Meta package with all essentials | Start here |
@nextrush/core | Application, middleware composition | Usually via nextrush |
@nextrush/router | Radix tree routing | Usually via nextrush |
@nextrush/types | TypeScript type definitions | Re-exported by nextrush; install directly for advanced package work |
@nextrush/errors | HTTP error classes | Usually via nextrush |
@nextrush/runtime | Runtime detection | Usually via adapter |
@nextrush/dev | Development server & build tools | Dev dependency |
Runtime Adapters
Connect NextRush to your runtime environment.
| Package | Runtime | Notes |
|---|---|---|
@nextrush/adapter-node | Node.js | Included in nextrush |
@nextrush/adapter-bun | Bun | Install separately |
@nextrush/adapter-deno | Deno | Install separately |
@nextrush/adapter-edge | Edge (Cloudflare, Vercel) | Install separately |
Middleware
Middleware packages for common HTTP concerns.
| Package | Purpose |
|---|---|
@nextrush/cors | Cross-Origin Resource Sharing |
@nextrush/helmet | Security headers |
@nextrush/body-parser | Request body parsing |
@nextrush/rate-limit | Rate limiting |
@nextrush/compression | Response compression |
@nextrush/cookies | Cookie handling |
@nextrush/request-id | Request ID generation |
@nextrush/timer | Response timing |
@nextrush/multipart | Multipart form parsing |
@nextrush/csrf | CSRF protection |
Plugins
Extend NextRush with additional capabilities.
| Package | Purpose |
|---|---|
@nextrush/controllers | Class-based controllers with DI |
@nextrush/logger | Structured logging |
@nextrush/static | Static file serving |
@nextrush/websocket | WebSocket support |
@nextrush/events | Event emitter integration |
@nextrush/template | Template engine integration |
Dependency Injection
For class-based applications with decorators.
| Package | Purpose |
|---|---|
@nextrush/di | Dependency injection container |
@nextrush/decorators | Controller, route, and guard decorators |
$ pnpm add @nextrush/di @nextrush/decorators @nextrush/controllers
Choosing Packages
Functional Style (Recommended for Most)
import { createApp, createRouter, listen } from 'nextrush';
import { cors } from '@nextrush/cors';
import { json } from '@nextrush/body-parser';
const app = createApp();
app.use(cors());
app.use(json());
const router = createRouter();
router.get('/users', (ctx) => ctx.json([]));
app.route('/', router);
await listen(app, 3000);Install:
$ pnpm add nextrush @nextrush/cors @nextrush/body-parser
Class-Based Style (For Larger Apps)
import { createApp, createRouter, listen } from 'nextrush';
import { controllersPlugin, Controller, Get, Service } from 'nextrush/class';
@Service()
class UserService {
findAll() {
return [{ id: 1, name: 'Alice' }];
}
}
@Controller('/users')
class UserController {
constructor(private users: UserService) {}
@Get()
findAll() {
return this.users.findAll();
}
}
const app = createApp();
const router = createRouter();
await app.plugin(controllersPlugin({ router, root: './src', prefix: '/api' }));
app.route('/', router);
await listen(app, 3000);Install:
$ pnpm add nextrush @nextrush/di @nextrush/decorators @nextrush/controllers
Non-Node.js Runtimes
For Bun, Deno, or Edge runtimes, install the specific adapter:
// Bun
import { createApp } from '@nextrush/core';
import { serve } from '@nextrush/adapter-bun';
const app = createApp();
serve(app, { port: 3000 });Install:
$ pnpm add @nextrush/core @nextrush/router @nextrush/adapter-bun
Package Size Philosophy
NextRush follows a strict size budget:
| Category | Max LOC | Rationale |
|---|---|---|
| Core packages | 500-1,500 | Foundation must be minimal |
| Adapters | ~500 | Thin adapters, no bloat |
| Middleware | ~300 | Single responsibility |
| Plugins | ~600 | Focused features |
This ensures:
- Fast installation
- Quick cold starts
- Low memory footprint
- Transparent auditing