Fixing Node-RED Context Loss After Restart
Learn how to diagnose and fix the loss of global and flow variables in Node-RED after a restart by configuring local filesystem context storage.
01 Aug 2026, 11:03 UTC

The Problem: Volatile Context State
You have configured global or flow-level variables in Node-RED to track state across different nodes. While these values work perfectly during a session, they vanish or revert to defaults every time the Node-RED service restarts or the hardware reboots. This forces your automation to lose its "memory," potentially triggering incorrect logic or resetting critical counters.
By default, Node-RED stores context in memory. To make this data survive a restart, you must explicitly configure context storage to use the local filesystem.
Diagnostic Matrix
Use this table to identify the likely cause of your state loss based on observable symptoms.
| Symptom | Likely Cause | Diagnostic Indicator |
|---|---|---|
Variables are undefined immediately after reboot. |
Default memory storage active. | settings.js lacks contextStorage config. |
| Logs show "Permission denied" during startup. | Filesystem permission error. | Node-RED user cannot write to the .node-red folder. |
| Values change randomly or revert to old states. | Instance conflict. | Two Node-RED instances pointing to one storage folder. |
| Storage is enabled, but specific keys disappear. | Logic-driven reset. | A function node is calling flow.set(key, undefined). |
Step-by-Step Recovery Process
1. Verify Current Storage Mode
Check the Node-RED startup logs (via journalctl -u nodered on Linux or the console window on Windows). Look for the context store initialization line.
- Expected:
[info] Context store: file - Warning: If you see
[info] Context store: memory, your settings are not configured for persistence.
2. Configure Local Filesystem Storage
You must modify the settings.js file. This file is typically located in ~/.node-red/settings.js.
Warning: Do not edit this file while Node-RED is running. A syntax error here will prevent the service from starting. Always create a backup copy before editing.
Find the contextStorage object and update it to use the localfilesystem module:
// In settings.js
contextStorage: {
default: {
module: "localfilesystem"
}
}
3. Validate Directory Permissions
Node-RED writes context data to JSON files within the user directory. Ensure the user running the Node-RED process has read/write access to the .node-red folder.
Run the following command on the host terminal to check ownership (replace nodered with your actual service user):
# Check ownership of the node-red directory
ls -ld ~/.node-red
If the directory is owned by root but the service runs as nodered, fix it with:
# Run as sudo/root
chown -R nodered:nodered ~/.node-red
4. Restart and Verify
Restart the Node-RED service to apply the changes. To verify the fix, create a temporary test flow:
- Add a Function Node with the following code:
global.set("persistence_test", Date.now()); return msg; - Deploy the flow and trigger the node once.
- Restart the Node-RED service.
- Add a Debug Node connected to a Function node that returns
global.get("persistence_test"). - Deploy and trigger. If the timestamp from before the restart appears, persistence is working.
Physical File Verification
You can confirm the data is physically written by inspecting the filesystem. Navigate to your Node-RED user directory and look for the context folder:
- Global state: Check
~/.node-red/context/global.json - Flow state: Check
~/.node-red/context/flow/<flow-id>.json
Open these files with a text editor; you should see the keys and values you set in your flows stored as JSON.
When to Escalate
If you have confirmed that localfilesystem is active and permissions are correct, but data still disappears, investigate these edge cases:
- Concurrent Instances: If you run Node-RED in a Docker container with a mapped volume, ensure no other container is mounting the same volume. Simultaneous writes to the JSON files can cause corruption or overwrites.
- Disk Quotas: Check if the disk is full or if a quota is preventing the JSON files from expanding.
- Logic Audit: Search your entire workspace for
.setcalls to see if a "reset" or "init" flow is clearing the context upon startup.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.