Installation
Usage
Import and configure theWorkflowModule in your NestJS application:
app.module.ts
API
WorkflowModule
NestJS module that provides workflow functionality.
WorkflowModule.forRoot(options?)
Configures and returns the workflow module.
WorkflowModuleOptions
Module configuration options.
string
Working directory for the NestJS application.Default:
process.cwd()string[]
Directories to scan for workflow files.Default:
['src']string
Output directory for generated workflow bundles.Default:
.nestjs/workflowboolean
Enable watch mode for development.Default:
false'es6' | 'commonjs'
SWC module compilation type.Set to
'commonjs' if your NestJS project compiles to CJS via SWC. When 'commonjs', the builder rewrites externalized imports in the steps bundle to use require() via createRequire, avoiding ESM/CJS named-export interop issues.Default: 'es6'string
Directory where NestJS compiles
.ts source files to .js (relative to workingDir).Used when moduleType is 'commonjs' to resolve compiled file paths. This should match the outDir in your tsconfig.json.Default: 'dist'boolean
Skip building workflow bundles (useful in production when bundles are pre-built).Default:
falseWorkflowController
Controller that handles the well-known workflow endpoints. Automatically registered by WorkflowModule.forRoot().
Routes
POST /.well-known/workflow/v1/step- Step execution endpointPOST /.well-known/workflow/v1/flow- Workflow execution endpointALL /.well-known/workflow/v1/webhook/:token- Webhook endpointGET /.well-known/workflow/v1/manifest.json- Workflow manifest (whenWORKFLOW_PUBLIC_MANIFEST=1)
NestLocalBuilder
Builder class for generating workflow bundles in NestJS applications.
configureWorkflowController(outDir)
Configures the workflow controller with the output directory. Called automatically by WorkflowModule.forRoot().
string
required
Output directory where workflow bundles are generated.
Configuration Examples
Basic Configuration
app.module.ts
Custom Directories
app.module.ts
CommonJS Configuration
For NestJS projects using SWC to compile to CommonJS:app.module.ts
Production Configuration
app.module.ts
How It Works
- Module Initialization:
WorkflowModule.forRoot()creates aNestLocalBuilderinstance - Build on Init: When the module initializes (
onModuleInit), it builds workflow bundles - Controller Registration: Registers
WorkflowControllerwith well-known workflow routes - Request Handling: Controller dynamically imports generated bundles and handles request/response conversion
Express/Fastify Compatibility
TheWorkflowController automatically detects and works with both Express and Fastify adapters:
- Converts platform-specific requests to Web API
Request - Converts Web API
Responseback to platform-specific response
CommonJS Interop
When usingmoduleType: 'commonjs', the builder:
- Generates ESM workflow bundles
- Rewrites externalized
.ts/.tsximports to userequire()viacreateRequire - Points imports to compiled
.jsfiles indistDir
_export() wrapper pattern.
Build Queue
UsescreateBuildQueue() to prevent concurrent builds when rebuilding workflows.