n8n expressions are small JavaScript snippets embedded in node parameters — they read $json for the current item, $node for the output of a specific node, $now for the current time, and $env for environment variables. The right answer is expressions for value transformation (renaming a field, formatting a date, computing a sum), a Code node for logic that needs more than 5 lines, and a Function node (deprecated) only for legacy workflows.
Table of contents
- The expression syntax — JavaScript in
{{ }} - The $json variable — the current item
- The $node variable — the output of a specific node
- The $now and DateTime variables — the date math
- The $env variable — environment variables
- The Code node — when to use it instead
- How this fits the rest of the stack
- FAQ
The expression syntax — JavaScript in {{ }}
An n8n expression is a JavaScript snippet wrapped in {{ }}. The expression is evaluated when the node runs, the result is used as the parameter value. The common pattern: {{ $json.email }} reads the email field from the current item, {{ $now.toFormat('yyyy-MM-dd') }} formats the current time as YYYY-MM-DD, {{ $json.amount * 1.1 }} adds 10% to the amount.
The right answer for a simple transformation is an expression — the team’s workflow is self-documenting, the parameter is right next to the field it transforms. The wrong answer is a Code node for a 1-line transformation — the team is paying for the Code node’s overhead for what an expression does in microseconds.
The $json variable — the current item
The $json variable is the current item’s JSON payload. The expression {{ $json.email }} reads the email field. The expression {{ $json.user.name }} reads a nested field. The right answer is $json for any transformation that uses the current item’s data. The wrong answer is to use a Code node for a 1-line $json.email read — the expression is faster and clearer.
The $node variable — the output of a specific node
The $node variable is the output of a specific node. The expression {{ $node["HTTP Request"].json["data"] }} reads the data field from the output of the node named HTTP Request. The right answer is $node when the team needs to reference data from a previous node, not just the current item. The gotcha: the node name is case-sensitive and must match the name in the workflow UI.
The $now and DateTime variables — the date math
The $now variable is the current time as a Luxon DateTime object. The right answer for date formatting is $now.toFormat('yyyy-MM-dd') (returns 2026-06-23), $now.toISO() (returns the full ISO string), or $now.toMillis() (returns the Unix timestamp). The right answer for date math is $now.plus({ days: 7 }) (a week from now), $now.startOf('month') (the first day of the current month), or $now.diff($json.created_at, 'days').days (the number of days between now and the created_at field).
The right answer for timezones is $now.setZone('America/New_York') — n8n uses Luxon’s setZone, and the timezone is the IANA name. The wrong answer is to assume the server’s timezone is the user’s — the workflow that runs in UTC produces a different date than the user expects.
The $env variable — environment variables
The $env variable is the workflow’s environment variables. The expression {{ $env.API_KEY }} reads the API_KEY env var, the expression {{ $env.WEBHOOK_URL }} reads the WEBHOOK_URL. The right answer is $env for any value that is set per-environment (API keys, webhook URLs, feature flags). The right answer for production is to set the env vars in the n8n instance, not in the workflow.
The Code node — when to use it instead
The Code node runs a JavaScript snippet on every item. The right answer is the Code node for logic that needs more than 5 lines — a complex transformation, an API call, a database query. The wrong answer is the Code node for a 1-line transformation — the expression is faster and self-documenting. The right answer is to put the Code node at the end of the workflow (the ‘transform’ step), not in the middle (where the team’s debugging is harder).
The gotcha: the Code node has two modes — ‘Run Once for Each Item’ and ‘Run Once for All Items’. The right answer is ‘Run Once for All Items’ for transformations that need to see the full dataset (e.g., sorting, deduplication), ‘Run Once for Each Item’ for per-item transformations.
How this fits the rest of the stack
The infrastructure question is a small piece of a larger pattern: the team’s runtime, storage, database, secret store, logs, and deployment platform are all parts of the same platform. The right answer is to model the full stack before the project ships, not after. The RunxBuild hosting calculator is the right place to do that exercise — pick the runtime, the memory tier, the storage, the secret store, and the egress, and the calculator shows what the deploy actually costs at the team’s actual usage.
Useful related references:
FAQ
What is an n8n expression?
An n8n expression is a small JavaScript snippet embedded in a node parameter, wrapped in {{ }}. The expression is evaluated when the node runs.
How do I read the current item’s data in n8n?
Use $json. The expression {{ $json.email }} reads the email field from the current item.
How do I read the output of a specific node in n8n?
Use $node["NodeName"].json["field"]. The node name is case-sensitive and must match the name in the workflow UI.
How do I format dates in n8n?
Use $now.toFormat('yyyy-MM-dd') for the Luxon format string. The right answer is toFormat for custom, toISO for ISO 8601, toMillis for Unix timestamp.
How do I add a duration to a date in n8n?
Use $now.plus({ days: 7 }) for a week from now. The right answer is plus for future, minus for past.
How do I use environment variables in n8n?
Use $env.API_KEY. The right answer is $env for any value that is set per-environment.
When should I use a Code node in n8n?
Use a Code node for logic that needs more than 5 lines — a complex transformation, an API call, a database query.
Can n8n expressions call external APIs?
Not directly. The right answer is to use the HTTP Request node for the API call, then an expression to read the response.