NextRush
Guides

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

npx nextrush dev

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

Build for production

npx nextrush build

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

Dev Server Options

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

nextrush dev options

PropertyTypeDescription
--port, -pnumber= 3000Server port
--watch, -wstring= src (or . if src/ missing)Path to watch (replaces default; repeatable)
--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.

Build Options

npx 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
--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: npx 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: ['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 dev

You should see:

⚡ NextRush Dev Server

  Runtime:  node v22.x.x
  Entry:    src/index.ts
  Port:     3000
  Watching: src

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

On this page