Skip to main content
The Node class is the foundation of all workflow nodes in CrystalFlow.

Class: Node

Properties

string
Unique identifier for the node instance. Auto-generated on creation.
string
Node type identifier (e.g., 'math.add'). Set via @defineNode decorator.
NodeMetadata
Node metadata including label, category, description, and port definitions.
NodeState
Current execution state: 'idle', 'executing', 'success', or 'error'.

Methods

execute()

Execute the node’s business logic. Must be implemented by all nodes.
Example:
Async execution:

validate()

Validate node configuration and inputs.
Returns: ValidationResult with isValid boolean and optional errors array. Example:

run()

Execute the node with validation and state management. Called by the execution engine.
ExecutionContext
Optional execution context providing variables and timing info.
Flow:
  1. Set state to 'executing'
  2. Call validate()
  3. Call execute()
  4. Set state to 'success' or 'error'
Example:

reset()

Reset node state to idle and clear outputs.
Example:

toJSON()

Serialize node to JSON format.
Returns: JSON representation with id, type, position, and data (inputs, outputs, properties). Example:

fromJSON()

Deserialize node from JSON format.
NodeJSON
JSON representation of the node.
Returns: New node instance with restored state. Example:

checkCancellation()

Check if execution has been cancelled. Throws CancellationError if cancelled.
Example:

Types

NodeMetadata

NodeState

ValidationResult

NodeJSON

Interface: IConditionalNode

Nodes implement this interface to enable conditional branching in workflows.

evaluateCondition()

Determines which branch should execute based on the node’s state.
Returns: The name of the output port representing the active branch. Requirements:
  • Must return a string matching an existing output port name
  • Called after execute() completes
  • Must be deterministic based on node state
  • Should not modify node state or perform side effects
Example Implementation:
Custom Conditional Node:
The execution engine uses evaluateCondition() to build and execute conditional branches. Only nodes connected to the returned output port will execute.
See also:

Examples

Basic Node

Async Node with Validation

Long-Running Node with Cancellation

Creating Custom Nodes

Learn to build custom nodes

Decorators

Decorator API reference

Workflow

Workflow class reference

Executor

Executor class reference