HeronJS v4
HeronJS is a TypeScript framework for modular Node.js applications. This documentation covers 4.7.0. Upgrade installed @heronjs/* packages together.
Start with Getting Started, or follow the Migration Guide when upgrading an existing application.
Application lifecycle
| Package | Responsibility |
|---|---|
@heronjs/common | Modules, typed DI, metadata, guards, shared contracts, logging, and the worker DI bridge |
@heronjs/core | Application startup, shutdown, HTTP hosting, datasources, cache, and extension composition |
@heronjs/express | Fastify-based HTTP controllers, hooks, private caching, and SSE |
@heronjs/gql | GraphQL schemas and resolvers |
@heronjs/trpc | tRPC queries, mutations, and subscriptions |
@heronjs/websocket | Native WebSocket gateways and handlers |
@heronjs/mcp | MCP tools, resources, and prompts |
@heronjs/acp | ACP agents and sessions |
@heronjs/ebs | Kafka, NATS, and AMQP messaging |
@heronjs/thread | Built-in worker pools and dedicated services |
Declare providers and protocol classes in @Module(...). Decorators record metadata; each application owns its container, registry, extensions, and resources. Importing a decorated class does not start it or register it in a process-wide container.
HeronJS.create() returns a configurable application. Set up shared server options with app.add(...) and register worker module sources with app.threads(...) before initialization. start() initializes providers, workers, global hooks, and extensions without binding HTTP. listen() initializes if necessary and opens the shared listener; it may follow start() without restarting resources. After initialization, only listener host/port can change.
Use await app.close() or await using app = await HeronJS.create(...) to shut down. Cleanup is asynchronous and idempotent, cancels owned work, and attempts remaining disposers after failures. Containers dispose constructed instances in reverse construction order. registerInstance leaves ownership with the caller; use registerOwnedInstance or onDispose for container-owned cleanup.
Endpoint transport and authentication belong on @MCP, @ACP, and @WebSocket. MCP/ACP endpoints default to HTTP. To use stdio, select transport: 'stdio' on one endpoint and pass runtime: {stdio: true} to create(). Other endpoints remain HTTP; only one endpoint per process can own stdin/stdout. Framework logs go to stderr while stdio is enabled.
What changes in 4.7.0
- Validate and transform inputs with optional Zod schemas across HTTP, GraphQL, tRPC, and WebSocket. Parsing supports async refinements and runs after authorization.
- Enforce every repeated and inherited guard policy; reject empty policies and conflicting application authentication declarations.
- Configure bounded WebSocket message queues, ACP prompt updates, and MCP execution and notification production. Await sends and honor cancellation.
Start with Input validation and the 4.7 migration steps.
Object APIs introduced in 4.6
Framework calls and callbacks use typed objects: for example, logger.info({message, data}), datasource({source, tenant}), and HTTP hooks receiving {request, response}. Worker dispatch uses run({request, options}), returning a cold Observable; use firstValueFrom when you need a Promise. Update protocol decorators and callbacks along with application code.
For upgrades from 4.3, also replace borrowResource with borrow and datasource forTenant with with({tenant}). See the 4.6 migration steps for call replacements and callback signatures.
Startup logging in 4.7.0
Startup output groups component names by kind while retaining detailed handler mappings and protocol resource rows. Read the logging guide for an example and output settings.
Upgrading from 4.2
- Configure protocol listeners through
protocolsinstead ofsubServer. - Compile worker definitions as separate ESM modules with your normal application build.
- Use readable logger messages and opt in to data/error redaction with
redact.
See the 4.2 to 4.3 migration steps.
Application features
- Declare worker requests with
@Taskand register definition files withapp.threads(...). - Bind messaging publishers and subscribers to adapter classes.
- Use WebSocket
@OnMessagefor a reply to the originating connection. - Import datasource and cache APIs from
@heronjs/core. - Use managed database connections with your chosen validation and migration tools.