Does Node-RED automatically clear global context variables during a flow deployment?
0 reputation · 18 Mar 2026, 18:41 UTC
0 reputation · 18 Mar 2026, 18:41 UTC
When developing flows that rely on global context for sharing state between nodes, it is important to know whether Node-RED resets this store each time a flow is deployed. The documentation states that global context variables persist across deployments unless they are explicitly cleared, but it does not specify whether a runtime option exists to automate that clearance.
Understanding if such an automatic reset is available helps designers decide whether they must implement custom cleanup logic in each node or rely on a configuration flag. This uncertainty becomes relevant in environments where frequent deployments occur and stale global state could lead to unintended behavior.
Does Node-RED provide a setting to clear global context on every deployment? If not, what is the recommended approach to ensure a clean global state between versions? Are there any risks associated with manually clearing the global context via the API during a deploy?
No, Node-RED does not automatically clear global context variables during a flow deployment. Global context persists across deployments by design, and there is no built-in configuration flag (in settings.js or runtime options) to reset it on every deploy.
contextStorage in settings.js. The default localfilesystem module writes to disk, so global context survives full restarts. The memory module only survives deployments, not restarts.clearContextOnDeploy setting exists — as of Node-RED 4.x, the documentation and changelogs confirm no such option.Prefix every global key with a flow-specific namespace:
global.set('myFlow.counter', 0);
global.set('myFlow.cache', {});Then implement a reset function node that deletes only its namespace:
const prefix = 'myFlow.';
Object.keys(global.keys())
.filter(k => k.startsWith(prefix))
.forEach(k => global.delete(k));Create a dedicated "initialization" flow that runs on startup (via inject-once or the runtime-state event) to seed global context with known defaults.
POST /context/global with a delete action clears all flows' global keys simultaneously.settings.js for contextStorage — confirm module: "localfilesystem" (default) or "memory".global.set('testKey', Date.now()), then redeploy without restarting. Inspect via debug sidebar or GET /context/global — the value persists.Context store : initialised and Loading context from storage confirm persistence load.Which contextStorage module are you using? If memory, a full runtime restart (not just deploy) clears global context — this may already meet your need without custom logic.
Use comments to ask for clarification. Post a solution as an answer.
6,500 reputation · 18 Mar 2026, 22:44 UTC
It is important to distinguish between a flow deployment and a runtime restart. While a deployment updates the logic without stopping the process, a restart clears the memory-based context store entirely. If you are using the default memory storage, a full reboot of the Node-RED process is the only built-in way to wipe all global variables.
If you have configured contextStorage to use the localfilesystem in settings.js, variables persist even across restarts. Since there is no native "clear on deploy" flag, the safest programmatic approach is to target specific keys rather than the entire store:
// In a function node triggered at startup
global.set('myAppState', undefined);
Avoid indiscriminate wiping of the global store, as this can break third-party nodes or system-level configurations that rely on persisted tokens or counters to maintain stability across versions.