Understanding the Differences Between $node and $() Expressions in n8n

Describe the problem/error/question

I am trying to understand the difference between these two expressions in n8n: $node["nodo"].json.elemento and $('nodo').item.json.elemento. Both seem to fetch an element from a previous node, but I’m noticing some inconsistencies in their behavior.

What is the error message (if any)?

No error message, but the behavior during the design phase of the flow differs. When I use $('nodo').item.json.elemento, it doesn’t show the result in the expression builder, though it does fetch the result during execution. In contrast, $node["nodo"].json.elemento shows the result during the design phase.

Additional Context:

Why does the expression constructor in n8n default to using the second form ($('nodo').item.json.elemento), and how can I make it default to the first form ($node["nodo"].json.elemento), which seems clearer to me?

Please share your workflow

(Workflow details omitted for brevity, but the main focus is on the usage of the mentioned expressions in accessing data from previous nodes.)

Share the output returned by the last node

Not applicable, as the question is more about expression behavior than specific output.

Information on your n8n setup

  • n8n version: last version
  • Database (default: SQLite): SQLite
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Synology NAS. DSM OS

Hi @MaaPer, the $node["node name"] has been deprecated as it’s somewhat prone to errors. The functional difference between $("node name") and $node["node name"] is that $("node name") makes uses of n8n’s item linking logic (also called paired items occasionally).

However, the legacy expression $node["node name"] will match items based on their index. This leads to errors if either the number or order of your items changes during a workflow. Consider a scenario where you receive a single message and then perform some sort of lookup, for example in a Google Sheet. Your initial trigger node will have one item, but your Google Sheet node may return multiple items. In subsequent nodes, using an expression like $node["your trigger node"] will be problematic. This is because for the first item that n8n gets from your Google Sheet, n8n would fetch the first item from your trigger node. This might work fine, but for your second item the lookup will fail because n8n will try to fetch the second item from your trigger node, which does not exist.

So I’d strongly suggest using any the expressions from the current docs whenever you can and avoid using the legacy expressions, even if it means you have to test your workflow to see the result.

1 Like