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
nextrush devThe CLI auto-detects your entry file, runtime, and TypeScript settings. No configuration required.
Build for production
nextrush buildCompiles TypeScript with SWC, emitting decorator metadata that DI containers require.
Dev Server Options
nextrush dev ./src/app.ts --port 4000 --inspectnextrush dev options
| Property | Type | Description |
|---|---|---|
--port, -p | number= 8080 | Server port |
--watch, -w? | string | Additional path to watch (repeatable). With no explicit path, the dev server watches imported files automatically instead. |
--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.
Watch strategy
With no --watch flag, the dev server watches imported files automatically — the portable
default across Node.js, Bun, and Deno. Passing one or more explicit --watch <path> flags
switches Node.js to path-scoped watching (--watch-path); if that flag is unsupported on the
current platform/Node version, the dev server falls back to the automatic mode rather than
crashing. Bun does not support explicit watch paths and always watches imported files.
Build Options
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 |
--dts | boolean= true | Generate .d.ts files |
--no-dts | boolean | Disable .d.ts generation |
--cache | boolean= true | Use incremental build cache |
--no-cache | boolean | Disable build cache |
--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: 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: ['config'], // additional paths to watch, beyond the automatic imported-files mode
},
build: {
outDir: 'dist',
target: 'es2022',
minify: false,
},
};CLI flags override config file values.
Verification
Run the dev server and confirm the output:
nextrush devYou should see:
⚡ NextRush Dev Server
Runtime: node v22.x.x
Entry: src/index.ts
Port: 8080
Local: http://127.0.0.1:8080
Watching: imported files (auto)If 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.
Dependency Injection & Scopes
Understand how DI and scopes work internally.
API Reference — Class Runtime
Full DI container and decorator API.
Deployment
Deploy your application to production.