GuidesAPI Development

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.ts entry file)
  • tsconfig.json — for class-based code (nextrush/class, DI), enable experimentalDecorators and emitDecoratorMetadata (the class-based / full scaffolds 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 dev

The CLI auto-detects your entry file, runtime, and TypeScript settings. No configuration required.

Build for production

nextrush build

Compiles TypeScript with SWC, emitting decorator metadata that DI containers require.

Dev Server Options

nextrush dev ./src/app.ts --port 4000 --inspect

nextrush dev options

PropertyTypeDescription
--port, -pnumber= 8080Server port
--watch, -w?stringAdditional path to watch (repeatable). With no explicit path, the dev server watches imported files automatically instead.
--inspectboolean= falseEnable Node.js inspector
--inspect-portnumber= 9229Inspector port
--no-clearbooleanDon't clear screen on start
--verbose, -vboolean= falseVerbose 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 es2022

nextrush build options

PropertyTypeDescription
--outDir, -ostring= distOutput directory
--target, -tstring= es2022ES target (es2020, es2021, es2022, esnext)
--sourcemapboolean= trueGenerate sourcemaps
--no-sourcemapbooleanDisable sourcemaps
--minify, -mboolean= falseMinify output
--no-decorator-metadatabooleanDisable decorator metadata emission
--dtsboolean= trueGenerate .d.ts files
--no-dtsbooleanDisable .d.ts generation
--cacheboolean= trueUse incremental build cache
--no-cachebooleanDisable build cache
--no-cleanbooleanDon't clean output directory before build
--verbose, -vboolean= falseVerbose output

Runtime Behavior

The CLI detects your runtime and adapts automatically:

RuntimeDev ServerProduction BuildDev Decorator Metadata
Node.js@swc-node/register (SWC)@swc/core transformEmitted
Bunbun --watch (native)Bun.build() (native)Emitted natively
Denodeno run --watch (native)npm:@swc/coreEmitted 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:

  1. package.json main or module field (converts dist/ paths to src/)
  2. src/index.ts, src/main.ts, src/app.ts, src/server.ts
  3. index.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:

nextrush.config.ts
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 dev

You 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

Was this helpful?

On this page