Creating Workflows
Workflows are the foundation of n8n automation. A workflow is a collection of nodes connected together to automate tasks and process data. This guide explains how workflows are structured and how to work with them programmatically.Workflow Structure
A workflow in n8n consists of several key components defined by theWorkflowParameters interface:
Key Components
- Nodes
- Connections
- Static Data
Nodes are the building blocks of workflows. Each node represents a specific action or operation.
Creating a Workflow
TheWorkflow class manages workflow execution and node relationships. Here’s how workflows are initialized:
1
Initialize Workflow
Create a new workflow instance with required parameters:
2
Node Type Resolution
During initialization, n8n resolves node types and applies default parameters:
3
Configure Connections
Connections are stored in two formats for efficient traversal:
Node Management
Accessing Nodes
Finding Trigger and Poll Nodes
Connection Traversal
Connections are indexed by source node by default. To find parent nodes, you must first invert the connections using
mapConnectionsByDestination().Finding Parent and Child Nodes
Finding Highest Parent Nodes
Start Node Selection
The workflow determines where to begin execution based on node types and connections:Static Data Management
Static data persists across workflow executions:Workflow Settings
Workflows can have custom settings that affect execution:Pin Data
Pin data allows you to use fixed data for specific nodes during development:Renaming Nodes
When renaming nodes, all references must be updated:Node names cannot use restricted JavaScript keywords like
hasOwnProperty, constructor, prototype, etc. These names could cause security issues.Best Practices
- Always validate node types: Check that node types exist before adding nodes to workflows
- Use workflow methods for traversal: Don’t manually traverse connections; use built-in methods
- Respect execution order: Understand that workflows can have different execution orders (
v1vs legacy) - Handle disabled nodes: Disabled nodes (
disabled: true) are skipped during execution - Consider timezone settings: Date operations use the workflow’s timezone setting
Next Steps
Nodes Overview
Learn about node types, parameters, and outputs
Expressions
Work with dynamic data using expressions
Error Handling
Handle errors and implement retry logic
Execution Modes
Understand different workflow execution modes