Overview
The environment module provides type-safe environment variable management with Zod-based validation. It ensures all required environment variables are present and valid before your plugin runs.This is an internal utility used by the SDK. Plugin developers don’t need to call
getEnv() directly - the SDK handles environment validation automatically when you call createPlugin().Functions
getEnv()
Retrieves and validates environment variables. The result is cached after the first call.Internal Usage
The SDK usesgetEnv() internally during plugin initialization:
Environment Variables
HUB_MODE
Type:"debug" | "release"
Default: "debug"
Description: The Hub Server runtime mode. Controls the operational mode of the plugin.
Validation:
- Must be either “debug” or “release”
- Defaults to “debug” if not specified
HUB_WS_URL
Type:string
Required: Yes
Description: The URL of the Hub Server WebSocket.
Validation:
- Must be a valid URL
- Protocol must be either
ws://orwss:// - Throws error if invalid: “HUB_WS_URL must be a valid WebSocket URL.”
HUB_DEBUG_API_KEY
Type:string
Required: Only in production
Description: The API key for the Hub Server.
Validation:
- Must be a non-empty string
- Required when
NODE_ENVis “production” - Optional in development/test environments
- Throws error if invalid: “HUB_DEBUG_API_KEY must be a string.”
DEBUG
Type:boolean
Default: true (when NODE_ENV !== "production")
Description: Whether to enable debug mode.
Validation:
- Automatically enabled when
NODE_ENVis not “production” - Can be explicitly set to “true” (case-insensitive) to enable
- Any other value is treated as
false
- Affects logging level (trace vs error)
- Controls verbose output in development
NODE_ENV
Type:"development" | "production" | "test"
Default: "development"
Description: The environment mode.
Validation:
- Must be one of: “development”, “production”, “test”
- Defaults to “development” if not specified
Validation Schema
The environment variables are validated using a Zod schema:Error Handling
If validation fails, the function:- Prints a formatted error message to console using
z.prettifyError() - Exits the process with code 1
Type Safety
The module extends Bun’sEnv interface to provide TypeScript autocomplete:
Caching
The environment is validated once and cached. Subsequent calls togetEnv() return the cached result without re-validation.