Dev Tools
Set up the NextRush CLI for development with hot reload and production builds with decorator metadata
Modern bundlers like esbuild and tsx strip decorator metadata that dependency injection needs. The @nextrush/dev CLI provides a hot-reloading dev server and a production build pipeline that preserves this metadata using SWC.
What You Will Build
A development workflow with a hot-reloading dev server and a production build that compiles TypeScript with SWC, preserving decorator metadata for DI.
Prerequisites
- Node.js 22+, Bun, or Deno installed
- An existing NextRush project (or a
src/index.tsentry file) tsconfig.json— for class-based code (nextrush/class, DI), enableexperimentalDecoratorsandemitDecoratorMetadata(theclass-based/fullscaffolds do this automatically). Functional scaffolds omit them on purpose because route handlers do not use decorators.
Installation
$ pnpm add -D @nextrush/dev
Step-by-Step Setup
Add scripts to package.json
{
"scripts": {
"dev": "nextrush dev",
"build": "nextrush build",
"start": "node dist/index.js"
}
}Start the dev server
npx nextrush devThe CLI auto-detects your entry file, runtime, and TypeScript settings. No configuration required.
Build for production
npx nextrush buildCompiles TypeScript with SWC, emitting decorator metadata that DI containers require.
Dev Server Options
npx nextrush dev ./src/app.ts --port 4000 --inspectnextrush dev options
| Property | Type | Description |
|---|---|---|
--port, -p | number= 3000 | Server port |
--watch, -w | string= src (or . if src/ missing) | Path to watch (replaces default; repeatable) |
--inspect | boolean= false | Enable Node.js inspector |
--inspect-port | number= 9229 | Inspector port |
--no-clear | boolean | Don't clear screen on start |
--verbose, -v | boolean= false | Verbose output |
The port also respects the PORT environment variable when --port is not set.
Build Options
npx nextrush build --outDir dist --minify --target es2022nextrush build options
| Property | Type | Description |
|---|---|---|
--outDir, -o | string= dist | Output directory |
--target, -t | string= es2022 | ES target (es2020, es2021, es2022, esnext) |
--sourcemap | boolean= true | Generate sourcemaps |
--no-sourcemap | boolean | Disable sourcemaps |
--minify, -m | boolean= false | Minify output |
--no-decorator-metadata | boolean | Disable decorator metadata emission |
--no-clean | boolean | Don't clean output directory before build |
--verbose, -v | boolean= false | Verbose output |
Runtime Behavior
The CLI detects your runtime and adapts automatically:
| Runtime | Dev Server | Production Build | Dev Decorator Metadata |
|---|---|---|---|
| Node.js | @swc-node/register (SWC) | @swc/core transform | Emitted |
| Bun | bun --watch (native) | Bun.build() (native) | Emitted natively |
| Deno | deno run --watch (native) | npm:@swc/core | Emitted natively |
Startup tsconfig validation
nextrush dev checks tsconfig.json when you use TypeScript + SWC. If only one of
experimentalDecorators / emitDecoratorMetadata is set to true, it warns so DI and
decorators do not half-fail. If both are omitted (typical functional scaffold), it stays
quiet — you are not using decorator metadata yet.
Entry File Detection
The CLI finds your entry file in this order:
package.jsonmainormodulefield (convertsdist/paths tosrc/)src/index.ts,src/main.ts,src/app.ts,src/server.tsindex.ts,main.ts,app.ts,server.ts
Override by passing the entry directly: npx nextrush dev ./src/app.ts
Configuration File
The CLI loads settings from nextrush.config.ts or a "nextrush" field in package.json:
export default {
dev: {
port: 4000,
watch: ['src', 'config'],
},
build: {
outDir: 'dist',
target: 'es2022',
minify: false,
},
};CLI flags override config file values.
Verification
Run the dev server and confirm the output:
npx nextrush devYou should see:
⚡ NextRush Dev Server
Runtime: node v22.x.x
Entry: src/index.ts
Port: 3000
Watching: srcIf you see "TypeInfo not known for X" at runtime while using nextrush/class, set both
experimentalDecorators and emitDecoratorMetadata to true in tsconfig.json. Import
nextrush/class (or your entry that loads it) so reflect-metadata runs — the nextrush/class
entry applies it for you.
Programmatic API
For build scripts, monorepo setups, or test harnesses:
import { dev, build, detectRuntime } from '@nextrush/dev';
// Dev server
await dev('./src/app.ts', { port: 4000, inspect: true });
// Production build
await build('./src/index.ts', { outDir: 'dist', minify: true });
// Runtime detection
const runtime = detectRuntime(); // 'node' | 'bun' | 'deno'Next Steps
Code Generators
Scaffold controllers, services, middleware, guards, and routes from the CLI.
Class-Based Controllers
Build APIs with decorators and DI.
DI & Decorators Architecture
Understand how DI and decorators work internally.
API Reference — DI
Full DI container and decorator API.
Deployment
Deploy your application to production.