CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-egg

A web application framework for Node.js with enterprise-grade development capabilities through a plugin-based architecture and convention-over-configuration approach

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

startup.mddocs/

Single Process Startup

Simple startup utilities for launching Egg.js applications in single-process mode, ideal for development and testing environments.

Capabilities

Start Egg Function

Main function for starting an Egg.js application in single process mode with both application and agent workers.

/**
 * Start egg application with single process mode
 * @param options - Startup configuration options
 * @returns Promise resolving to SingleModeApplication instance
 */
async function startEgg(options?: StartEggOptions): Promise<SingleModeApplication>;

/**
 * Alias for startEgg function
 * @param options - Same as startEgg options
 * @returns Promise resolving to SingleModeApplication instance
 */
const start: typeof startEgg;

interface StartEggOptions {
  /** Specify framework that can be absolute path or npm package */
  framework?: string;
  /** Directory of application, default to process.cwd() */
  baseDir?: string;
  /** Ignore single process mode warning */
  ignoreWarning?: boolean;
  /** Process mode, always 'single' for this function */
  mode?: 'single';
  /** Environment name */
  env?: string;
  /** Plugin configuration override */
  plugins?: EggPlugin;
}

Usage Examples:

import { startEgg } from "egg";

// Basic startup
const app = await startEgg();
console.log('Application started on port 7001');

// Startup with custom options
const app = await startEgg({
  baseDir: '/path/to/my/app',
  env: 'development',
  framework: 'egg',
  ignoreWarning: true
});

// Access both app and agent
console.log('App ready:', app.ready);
console.log('Agent ready:', app.agent.ready);

// Graceful shutdown
process.on('SIGTERM', async () => {
  await app.close();
});

Single Mode Interfaces

Type definitions for single-process mode applications that combine both application and agent functionality.

/**
 * Application instance in single mode with agent reference
 */
interface SingleModeApplication extends Application {
  /** Agent worker instance */
  agent: SingleModeAgent;
}

/**
 * Agent instance in single mode with application reference
 */
interface SingleModeAgent extends Agent {
  /** Application worker instance */
  app: SingleModeApplication;
}

Usage Examples:

import { startEgg, type SingleModeApplication } from "egg";

const app: SingleModeApplication = await startEgg({
  baseDir: process.cwd()
});

// Access application functionality
app.use(async (ctx, next) => {
  ctx.body = 'Hello Egg.js';
  await next();
});

// Access agent functionality
app.agent.messenger.broadcast('custom-event', { data: 'test' });

// Both app and agent are cross-referenced
console.log(app.agent.app === app); // true
console.log(app.agent.application === app); // true

Framework Detection

The startup process automatically detects the framework configuration from package.json if not explicitly provided.

Usage Examples:

// package.json configuration
{
  "name": "my-egg-app",
  "egg": {
    "framework": "my-custom-framework"
  }
}

// Startup will automatically use the framework from package.json
const app = await startEgg({
  baseDir: '/path/to/app'
  // framework is auto-detected from package.json
});

// Or explicitly override
const app = await startEgg({
  baseDir: '/path/to/app',
  framework: 'egg' // Override package.json setting
});

Lifecycle Management

Single process applications handle the complete lifecycle of both workers.

Usage Examples:

import { startEgg } from "egg";

async function bootstrap() {
  const app = await startEgg({
    baseDir: process.cwd(),
    env: process.env.NODE_ENV || 'development'
  });
  
  // Both agent and application are ready
  console.log('Agent ready:', await app.agent.ready());
  console.log('Application ready:', await app.ready());
  
  // Listen for egg-ready event
  app.messenger.on('egg-ready', () => {
    console.log('All workers ready');
  });
  
  return app;
}

// Graceful shutdown handling
async function shutdown(app: SingleModeApplication) {
  console.log('Shutting down...');
  
  // Close application (will also close agent in single mode)
  await app.close();
  
  console.log('Shutdown complete');
  process.exit(0);
}

// Usage
const app = await bootstrap();

process.on('SIGTERM', () => shutdown(app));
process.on('SIGINT', () => shutdown(app));

Types

type EggEnvType = 'local' | 'unittest' | 'prod' | string;

interface EggPluginItem {
  env?: EggEnvType[];
  path?: string;
  package?: string;
  enable?: boolean;
}

interface EggPlugin {
  [key: string]: EggPluginItem | boolean | undefined;
  onerror?: EggPluginItem;
  session?: EggPluginItem;
  i18n?: EggPluginItem;
  watcher?: EggPluginItem;
  multipart?: EggPluginItem;
  security?: EggPluginItem;
  development?: EggPluginItem;
  logrotator?: EggPluginItem;
  schedule?: EggPluginItem;
  static?: EggPluginItem;
  jsonp?: EggPluginItem;
  view?: EggPluginItem;
}

Install with Tessl CLI

npx tessl i tessl/npm-egg

docs

application.md

base-classes.md

configuration.md

context.md

http-client.md

index.md

loaders-errors.md

startup.md

tile.json