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.
Module configuration options.
Working directory for the NestJS application.Default:
process.cwd()Directories to scan for workflow files.Default:
['src']Output directory for generated workflow bundles.Default:
.nestjs/workflowEnable watch mode for development.Default:
falseSWC 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'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'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().
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.