Files
n8n-docs/docs/code-examples/methods-variables.md
Deborah Barnard d3b4f5a888 fix links
2022-08-31 14:32:04 +01:00

4.2 KiB

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, and whether they're available in the expressions editor, Function node, or both.

For usage examples, refer to Expressions examples and JavaScript examples.

Node input

Method Description Availability
$binary Shorthand for $input.item.binary. Incoming binary data from a node Expressions editor
$data Incoming raw data from a node. Both
$input.item The paired item. This is the input item that the previous node used to produce this item. Refer to Item linking for more information on paired items and item linking. Expressions editor
$input.all() All input items. Both
$input.first() First input item. Both
$input.last() Last input item. Both
$input.params Both
$input.context Both
$json Shorthand for $input.item.json. Incoming JSON data from a node Expressions editor

Node output

Method Description Availability
$("<node-name>").all(branchIndex?, runIndex?) Returns all items from a given node. Replaces $items. Both
$("<node-name>").first(branchIndex?, runIndex?) The first item output by the given node Both
$("<node-name>").last(branchIndex?, run Index?) The last item output by the given node. Both
$("<node-name>").item The paired item. This is the input item that the previous node used to produce this item. Refer to Item linking for more information on paired items and item linking. Expressions editor
$("<node-name>").params
$("<node-name>").context

Working with data

Method Description Availability
$evaluateExpression Evaluates a string as an expression Both
$jmespath() Perform a search on a JSON object using JMESPath. Both
$now A Luxon object containing the current timestamp. Equivalent to DateTime.now(). Both
$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 }). Both

n8n data

This includes:

  • Access to n8n environment variables for self-hosted n8n.
  • Metadata about workflows, executions, and nodes.
Method Description Availability
$env Contains environment variables. Both
$execution.id The unique ID of the current workflow execution. Both
$execution.mode Both
$execution.resumeUrl The webhook URL to call to resume a waiting workflow. Both
$parameters Parameters of the current node.
$position The index of an item in a list of items.
$prevNode.name Note that $prevNode always takes the first input. This is important when using it in a node with multiple inputs, such as the Merge node. Both
$prevNode.outputIndex Note that $prevNode always takes the first input. This is important when using it in a node with multiple inputs, such as the Merge node. Both
$prevNode.runIndex Note that $prevNode always takes the first input. This is important when using it in a node with multiple inputs, such as the Merge node. Both
$runIndex How many times n8n has executed the node. Zero-based (the first run is 0, the second is 1, and so on). Both
$workflow.active Whether the workflow is active (true) or not (false). Both
$workflow.id The workflow ID. Both
$workflow.name The workflow name. Both