/n8n-tutorials

How to use static data in n8n?

Learn how to use static data in n8n to store values, persist workflow information, and simplify automation setup.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free consultation

How to use static data in n8n?

To use static data in n8n, you store it on the workflow level using the built‑in $input.item.json-like object called $workflow.staticData. n8n keeps this data between workflow executions, so you can read and write to it without a database. It’s meant for small, simple state like counters, timestamps, or configuration values you don’t want hard‑coded in nodes.

 

What Static Data Is (and Why It Matters)

 

Static data is a special JSON object attached to a workflow. Unlike normal node data, which only exists during a single run, static data is persisted by n8n and is available on the next execution. Think of it as tiny permanent storage built into the workflow.

You access it in expressions or in Function / Function Item nodes through $workflow.staticData. If the workflow uses triggers (Cron, Webhook, etc.), static data will survive between runs as long as your n8n instance can persist executions (most setups do).

  • Use cases: counters, remembering last fetched IDs, storing config, caching.
  • Not for: large datasets, logs, secrets, anything requiring heavy writes.

 

How to Read and Write Static Data

 

You typically interact with it inside a Function or Function Item node. Here’s a clean example that increments a counter:

// Access staticData in "global" mode (persists across executions)
const data = $workflow.staticData;

// Initialize if missing
if (!data.counter) {
  data.counter = 0;
}

// Update it
data.counter++;

// Return current counter
return [{ counter: data.counter }];

This counter will survive every time your workflow runs. No database needed.

 

Static Data Modes: Global vs. Node

 

Static data comes in two flavors:

  • $workflow.staticData: shared across the entire workflow. Most common.
  • $node["NodeName"].staticData: scoped to a specific node. Rarely used but available if you need node‑local state.

Both persist across executions. Global is what most production workflows use.

 

Using Static Data in Expressions

 

You can also read static data directly in UI expressions without a Function node. For example:

// Example expression
{{$workflow.staticData.lastRunTimestamp}}

This is helpful if you store configuration values and want to reference them anywhere.

 

When Static Data Updates Persist

 

Static data only saves when the workflow successfully finishes. If the workflow errors, the changes to static data are not written. This is intentional so you don’t corrupt your “saved state” mid‑execution.

  • A normal successful run → static data is saved.
  • A failed run → static data reverts to the previous saved version.

This behavior affects things like counters or pagination trackers, so plan accordingly.

 

Important Production Considerations

 

  • Static data resets if you export the workflow JSON (it is not included in the export).
  • Static data is stored in your n8n database, so it survives restarts.
  • Not designed for large objects (keep it small: numbers, small strings, a few keys).
  • Don’t use it for secrets — use Credentials.
  • Don’t use it for high‑frequency writes — there’s a small write cost at the end of every run.

 

Simple Real-Life Example: Remember Last Processed ID

 

This is common when pulling from an API that doesn’t support webhooks.

const data = $workflow.staticData;

// read last ID or set default
const lastId = data.lastId || 0;

// call your API here (this is an example)
const newId = lastId + 5; // pretend we got new data

// store the updated ID
data.lastId = newId;

// output something
return [{ lastProcessed: newId }];

This makes sure the next time the workflow runs, it knows where it left off.

 

In short: using static data in n8n is the simplest way to give your workflow memory. It’s small, reliable, and perfect for lightweight state that needs to persist across executions.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022