> ## Documentation Index
> Fetch the complete documentation index at: https://docs.membrane.agency/llms.txt
> Use this file to discover all available pages before exploring further.

# Control Nodes

Control nodes manage the flow of execution, transform data, and implement conditional logic. They help you build complex workflows with branching, filtering, and iteration.

<br />

## Transform Data

**Type:** `transform-data`

The Transform Data node transforms input into a new data structure. This is one of the most commonly used nodes, essential for reshaping data between different formats.

```yaml theme={null}
transform:
  type: transform-data
  name: Format Contact Data
  config:
    output:
      fullName:
        $eval:
          $concat:
            - $var: input.trigger.fields.firstName
            - ' '
            - $var: input.trigger.fields.lastName
      email:
        $var: input.trigger.fields.email
      createdAt:
        $eval:
          $now: {}
      metadata:
        source: external-app
        syncedAt:
          $eval:
            $now: {}
```

The `output` configuration defines the structure of the transformed data. You can use variables (`$var`), expressions (`$eval`), or static values.

**Output:**

Returns the transformed object as specified in the `output` configuration:

```javascript theme={null}
{
  fullName: 'John Doe',
  email: 'john@example.com',
  createdAt: '2024-01-15T10:30:00Z',
  metadata: {
    source: 'external-app',
    syncedAt: '2024-01-15T10:30:00Z'
  }
}
```

<br />

## Filter

**Type:** `filter`

The Filter node conditionally allows data to continue through the flow. Only inputs that match the filter criteria are passed to downstream nodes.

```yaml theme={null}
filter:
  type: filter
  name: Only Active Contacts
  config:
    filter:
      $eval:
        $var: input.findContact.fields.status
      $eq: active
```

**Configuration options:**

* **`filter`** – Filter expression using evaluation syntax (supports `$eq`, `$gt`, `$and`, `$or`, etc.)

**Output:**

The filter node passes through the input unchanged if it matches the filter. If the input doesn't match, no output is produced and the flow stops for that input.

<br />

## For Each

**Type:** `for-each-v2`

The For Each node executes a subset of flow nodes for each item in a list, then aggregates their outputs. This is essential for processing arrays of data.

```yaml theme={null}
forEach:
  type: for-each-v2
  name: Process Each Contact
  config:
    items:
      $var: input.listContacts
    rootNodeKey: processContact
  links:
    - key: summary

processContact:
  type: transform-data
  name: Transform Contact
  config:
    output:
      id:
        $var: input.forEach.item.id
      fullName:
        $eval:
          $concat:
            - $var: input.forEach.item.fields.firstName
            - ' '
            - $var: input.forEach.item.fields.lastName

summary:
  type: transform-data
  name: Create Summary
  config:
    output:
      processed:
        $var: input.forEach
      normalizedContacts:
        $var: input.forEach.processContact
```

**Configuration options:**

* **`items`** – Array of items to iterate over (usually from a previous node's output)
* **`rootNodeKey`** – Key of the first node inside the For Each loop

**How it works:**

1. The For Each node receives a list of items
2. For each item, it executes the nodes inside the loop (starting from `rootNodeKey`)
3. Inside the loop, the current item is available as `input.forEach.item` (where `forEach` is the key of your for-each node)
4. All nodes inside the loop run for each item
5. After all items are processed, outputs are aggregated into a list

**Accessing the current item:**

Inside the For Each loop, access the current item:

```yaml theme={null}
$var: input.forEach.item
$var: input.forEach.item.id
$var: input.forEach.item.fields.email
```

**Output structure:**

The For Each node outputs an object with keys matching the nodes inside the loop, and values being arrays of their outputs:

```javascript theme={null}
{
  processContact: [
    { id: '1', fullName: 'John Doe' },
    { id: '2', fullName: 'Jane Smith' }
  ],
  normalizedContacts: [
    { id: '1', fullName: 'John Doe' },
    { id: '2', fullName: 'Jane Smith' }
  ]
}
```
