Skip to content

Built-in methods and variables#

n8n provides built-in methods and variables for working with data and accessing n8n data. This document provides a reference list of available methods and variables, with a short description. Note that some methods and variables aren't available in the Code node.

Current node input#

Method Description Available in Code node?
$binary Shorthand for $input.item.binary. Incoming binary data from a node ❌
$input.item The input item of the current node that's being processed. Refer to Item linking for more information on paired items and item linking. ❌
$input.all() All input items in current node. ✅
$input.first() First input item in current node. ✅
$input.last() Last input item in current node. ✅
$input.params Object containing the query settings of the previous node. This includes data such as the operation it ran, result limits, and so on. ✅
$json Shorthand for $input.item.json. Incoming JSON data from a node. Refer to Data structure for information on item structure. ❌
$input.context.noItemsLeft Boolean. Only available when working with the Split in Batches node. Provides information about what's happening in the node, allowing you to see if the node is still processing items. ✅

Output of other nodes#

Method Description Available in Code node?
$("<node-name>").all(branchIndex?, runIndex?) Returns all items from a given node. ✅
$("<node-name>").first(branchIndex?, runIndex?) The first item output by the given node ✅
$("<node-name>").last(branchIndex?, run Index?) The last item output by the given node. ✅
$("<node-name>").item The linked item. This is the item in the specified node used to produce the current item. Refer to Item linking for more information on item linking. ❌
$("<node-name>").params Object containing the query settings of the given node. This includes data such as the operation it ran, result limits, and so on. ✅
$("<node-name>").context Only available when working with the Split in Batches node. Provides information about what's happening in the node, allowing you to see if the node is still processing items. ✅
$("<node-name>").itemMatching(currentNodeinputIndex) Use instead of $("<node-name>").item in the Code node if you need to trace back from an input item. ✅

Date and time#

Method Description Available in Code node?
$now A Luxon object containing the current timestamp. Equivalent to DateTime.now(). ✅
$today A Luxon object containing the current timestamp, rounded down to the day. Equivalent to DateTime.now().set({ hour: 0, minute: 0, second: 0, millisecond: 0 }). ✅

n8n metadata#

This includes:

  • Access to n8n environment variables for self-hosted n8n.
  • Metadata about workflows, executions, and nodes.
Method Description Available in Code node?
$env Contains environment variables. ✅
$execution.id The unique ID of the current workflow execution. ✅
$execution.mode Whether the execution was triggered automatically, or by manually running the workflow. Possible values are test and production. ✅
$execution.resumeUrl The webhook URL to call to resume a workflow waiting at a Wait node. ✅
$getWorkflowStaticData(type) View an example. Static data isn't available when testing workflows. The workflow must be active and called by a trigger or webhook to save static data. This gives access to the static workflow data. ✅
$itemIndex The index of an item in a list of items. ❌
$prevNode.name The name of the node that the current input came from. When using the Merge node, note that $prevNode always uses the first input connector. ✅
$prevNode.outputIndex The index of the output connector that the current input came from. Use this when the previous node had multiple outputs (such as an If or Switch node). When using the Merge node, note that $prevNode always uses the first input connector. ✅
$prevNode.runIndex The run of the previous node that generated the current input. When using the Merge node, note that $prevNode always uses the first input connector. ✅
$runIndex How many times n8n has executed the current node. Zero-based (the first run is 0, the second is 1, and so on). ✅
$workflow.active Whether the workflow is active (true) or not (false). ✅
$workflow.id The workflow ID. ✅
$workflow.name The workflow name. ✅

Advanced#

Method Description Available in Code node?
$evaluateExpression Evaluates a string as an expression ✅
$jmespath() Perform a search on a JSON object using JMESPath. ✅