Better way to refere the parent node: Current or direct name?

Hi! After seeing how contributors work with workflows I noticed that they might use node name addressing for incoming data instead of Current. Is it the proper way to organize node addressing?

It might be useful when you moving nodes along the workflow while building. Thus you will never lose the incoming data.

Are there any caveeats to always use node addressing? There must be some benefit behind using Current notation.

The “issue” with $node it’s that it always refers to the first output of the node. This is in a “problem” in e.x: the IF node, if you want to reference the data of the false output. To avoid that, $json was created. $json, does not take into consideration the index in the output of any node but just the input of the node where is used.

  • $json: Incoming JSON data of a node
  • $node: Data of other nodes (binary, context, json, parameter, runIndex)

Check the example workflow below and you are going to notice the “issue” with the $node. I think it’s easier to understand it if you see the issue in a workflow. Notice the output of the Set2 node.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        -90,
        230
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      id: 1,\n      active: true,\n    }\n  },\n    {\n    json: {\n      id: 2,\n      active: false,\n    }\n  }\n]"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        220,
        230
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$node[\"Function\"].json[\"active\"]}}",
              "value2": true
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        490,
        230
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [],
          "number": [
            {
              "name": "id",
              "value": "={{$node[\"IF\"].json[\"id\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        760,
        120
      ]
    },
    {
      "parameters": {
        "values": {
          "number": [
            {
              "name": "id",
              "value": "={{$node[\"IF\"].json[\"id\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        760,
        350
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Now I see the point and understand better the need of Current data, thank you.

Also helpful if the node has multiple input connections like for example when you have a loop.

1 Like