API ReferencePlugins
Plugin Packages
Extend NextRush with controllers, logging, static files, WebSocket, events, and templates.
NextRush plugins extend your application with additional capabilities. Each plugin integrates with the core application through the standardized plugin interface.
Available Plugins
Loading diagram...
Quick Reference
| Package | Purpose | Use Case |
|---|---|---|
| @nextrush/controllers | Decorator-based controllers | Structured REST APIs |
| @nextrush/logger | Request logging | Observability, debugging |
| @nextrush/static | Static file serving | Frontend assets, downloads |
| @nextrush/websocket | Real-time communication | Chat, live updates |
| @nextrush/events | Event emitter | Decoupled architecture |
| @nextrush/template | HTML rendering | Server-side pages |
Installation
Install plugins as needed:
$ pnpm add @nextrush/controllers @nextrush/logger
Plugin Interface
All NextRush plugins implement a consistent interface:
interface Plugin {
name: string;
version?: string;
install(app: Application): void | Promise<void>;
destroy?(): void | Promise<void>;
}Using Plugins
import { createApp } from '@nextrush/core';
import { createRouter } from '@nextrush/router';
import { controllersPlugin } from '@nextrush/controllers';
import { eventsPlugin } from '@nextrush/events';
const app = createApp();
const router = createRouter();
// Register plugins
await app.plugin(controllersPlugin({ router, root: './src', prefix: '/api' }));
app.plugin(eventsPlugin());Plugin Categories
Architecture Plugins
These plugins add structural patterns:
- Controllers — Class-based route handlers with decorators
- Events — Decoupled communication between components
Feature Plugins
These plugins add capabilities:
- Logger — Request/response logging
- Static — File serving
- WebSocket — Real-time communication
- Template — HTML rendering
Combining Plugins
Plugin registration order matters. Middleware plugins (logger, static) should be registered before route-handling plugins (controllers).
Plugins work together:
import { createApp } from '@nextrush/core';
import { createRouter } from '@nextrush/router';
import { controllersPlugin } from '@nextrush/controllers';
import { logger } from '@nextrush/logger';
import { serveStatic } from '@nextrush/static';
const app = createApp();
const router = createRouter();
// Request logging
app.use(logger());
// Static files
app.use(serveStatic({ root: './public' }));
// API controllers
await app.plugin(
controllersPlugin({
router,
root: './src',
prefix: '/api',
})
);Creating Custom Plugins
Build your own plugins:
import type { Plugin } from '@nextrush/types';
const myPlugin: Plugin = {
name: 'my-plugin',
version: '1.0.0',
install(app) {
// Add middleware
app.use(async (ctx) => {
ctx.state.myValue = 'hello';
await ctx.next();
});
},
destroy() {
// Cleanup on shutdown
},
};
app.plugin(myPlugin);Next Steps
Explore individual plugin documentation:
- Controllers — Structured APIs with decorators
- Logger — Request logging
- Static — File serving
- WebSocket — Real-time features