5 n8n expressions I use in every production workflow (and you probably should too)

After building and shipping dozens of n8n workflows in production - chatbots, automation pipelines, error monitoring systems - I keep coming back to the same handful of expressions that make everything cleaner and more reliable.

Here are 5 that I consider essential:

1. $now.toISO() vs $now.format()

Use $now.toISO() when you need a standardized timestamp for databases or APIs. Use $now.format(‘DD/MM/YYYY HH:mm’) for human-readable output in notifications or logs. Mixing these up causes subtle bugs that are hard to trace.

2. $json.fieldName ?? ‘default value’

The nullish coalescing operator is your friend. Instead of checking if a field exists before using it, just use ?? to provide a fallback. {{ $json.customerName ?? ‘Unknown Customer’ }} will never break your workflow when data is missing.

3. $items().length for batch counting

Inside a Loop Over Items node, $items().length tells you the total batch size. Combined with $itemIndex, you can build progress tracking, send “X of Y completed” messages, or trigger different logic for the last item.

4. $workflow.id and $execution.id for logging

Always include $workflow.id and $execution.id in your error alert messages and logs. When something breaks at 3am, these two values let you find the exact failed run in seconds instead of guessing.

5. Object.entries($json).filter(…) in Code nodes

When you need to dynamically process fields without knowing the key names upfront, Object.entries($json) turns your JSON into an array of [key, value] pairs you can filter, map, or transform. This is essential for building flexible workflows that adapt to varying data structures.

Which expressions do you use most in production? Would love to hear what the community has found useful.

1 Like