Course/Chapter 3/5. Variables & Expressions
    beginner
    Chapter 3: Understanding Workflows

    5. Variables & Expressions

    Use n8n's expression language for dynamic data.

    20m Lesson 5 of 6

    n8n's expression system gives you access to powerful built-in functions and variables that make your workflows dynamic and flexible.

    Built-in Variables

    • - `$json` — Current item's JSON data
    • - `$binary` — Current item's binary data
    • - `$env` — Environment variables
    • - `$workflow` — Workflow metadata (id, name, active)
    • - `$execution` — Current execution metadata
    • - `$now` — Current timestamp
    • - `$today` — Current date (start of day)

    Code Examples

    Built-in Functions
    javascript
    // String functions
    {{ $json.name.toUpperCase() }}
    {{ $json.email.includes("@gmail") }}
    {{ $json.text.replace(/\n/g, "<br>") }}
    
    // Date functions (Luxon)
    {{ $now.toFormat("yyyy-MM-dd") }}
    {{ $now.minus({ days: 7 }).toISO() }}
    {{ DateTime.fromISO($json.date).diffNow("days").days }}
    
    // Array functions
    {{ $json.tags.includes("urgent") }}
    {{ $json.scores.reduce((a,b) => a+b, 0) / $json.scores.length }}
    
    // Workflow variables
    {{ $workflow.name }}
    {{ $execution.id }}

    Pro Tips

    • 💡Use $env to store API keys and configuration that changes between environments

    Comprehension Quiz

    Answer 2 of 2 correctly to unlock lesson completion.

    1. What does $now return in n8n?

    2. How do you access environment variables in expressions?

    Pass the quiz above to unlock lesson completion