or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

base-command.mdcoverage-testing.mddebug-command.mddevelopment-server.mdindex.mdtest-runner.md
tile.json

development-server.mddocs/

Development Server

The development server capability provides a comprehensive local development environment for Egg.js applications with hot reload, clustering support, and automatic configuration detection.

Capabilities

DevCommand

Starts a development server with master/agent/worker cluster architecture on the local environment.

/**
 * Development server command for Egg.js applications
 * Extends BaseCommand with development-specific options
 */
class DevCommand extends BaseCommand {
  /** Listening port, default 7001 or auto-detected available port */
  port: number;
  
  /** Number of app workers, default 1 at local mode */
  workers: number;
  
  /** Framework path (absolute path or npm package), defaults to 'egg' */
  framework: string;
  
  /** Start sticky cluster server for load balancing, default false */
  sticky: boolean;
  
  /**
   * Executes the development server startup process
   * Sets NODE_ENV to development and starts cluster with configured options
   */
  run(): Promise<void>;
  
  /**
   * Formats egg start options with port detection and configuration loading
   * @returns Promise resolving to egg cluster start options
   */
  protected formatEggStartOptions(): Promise<EggStartOptions>;
}

interface EggStartOptions {
  baseDir: string;
  workers: number;
  port: number;
  framework: string;
  typescript: boolean;
  tscompiler: string;
  sticky: boolean;
}

Port Detection

The development server automatically detects available ports using the following priority:

  1. Explicitly provided --port option
  2. Configuration from config/config.*.js files (cluster.listen.port)
  3. EGG_BIN_DEFAULT_PORT environment variable
  4. Default port 7001
  5. Next available port if 7001 is in use
/**
 * Port detection and configuration loading process
 * Uses @eggjs/utils for configuration reading and detect-port for availability
 */
interface PortDetectionProcess {
  /** Reads egg configuration for the local environment */
  getConfig(options: { framework: string; baseDir: string; env: string }): Promise<any>;
  
  /** Detects next available port starting from the default */
  detectPort(defaultPort: number | string): Promise<number>;
}

Usage Examples:

# Start with default settings
egg-bin dev

# Specify port and workers
egg-bin dev --port 8000 --workers 4

# Use custom framework
egg-bin dev --framework ./my-custom-egg

# Enable sticky sessions for load balancing
egg-bin dev --sticky

# TypeScript development with debugging
egg-bin dev --typescript --inspect

Framework Configuration

The development server supports custom Egg.js frameworks and automatic framework detection.

/**
 * Framework path resolution using @eggjs/utils
 * Resolves relative paths, npm packages, and absolute paths
 */
interface FrameworkResolution {
  /** Resolves framework path from various input formats */
  getFrameworkPath(options: {
    framework?: string;
    baseDir: string;
  }): string;
}

Environment Configuration

The development server automatically configures the environment for optimal development:

/**
 * Development environment configuration
 * Sets up NODE_ENV, timeouts, and process management
 */
interface DevEnvironment {
  /** Set to 'development' for egg environment detection */
  NODE_ENV: string;
  
  /** Master process close timeout (1000ms for fast restarts) */
  EGG_MASTER_CLOSE_TIMEOUT: string;
  
  /** TypeScript compilation flag when enabled */
  EGG_TYPESCRIPT?: string;
}

Cluster Management

The development server uses a cluster script for process management:

/**
 * Cluster startup script that receives serialized options
 * Located at scripts/start-cluster.js
 */
interface ClusterScript {
  /** Parses JSON options and starts egg cluster */
  startCluster(options: EggStartOptions): void;
}

Script Location: scripts/start-cluster.js

VSCode Integration

For debugging with VSCode, create .vscode/launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Egg Debug",
      "runtimeExecutable": "npm",
      "runtimeArgs": ["run", "dev", "--", "--inspect-brk"],
      "console": "integratedTerminal",
      "restart": true,
      "protocol": "auto",
      "port": 9229,
      "autoAttachChildProcesses": true
    }
  ]
}

Advanced Configuration

The development server supports advanced configuration through package.json:

{
  "egg": {
    "typescript": true,
    "tscompiler": "@swc-node/register",
    "require": ["./app/extend/helper.js"],
    "revert": ["CVE-2023-46809"]
  }
}