Losing global context variable

What can be a reason for loosing global context variables? I checked uptime....and server hasn't rebooted? How can be sure, that I will have particular values alway in global variable?
I am thinking to storing it locally in the file every hour for example and then load it after reboot?
What is your idea about that?
Thank you in advance!

Have a look here:
https://nodered.org/docs/api/context/

You can simply use the filingsystem context store as seen in the link that Garry provided. You can use the same context store type multiple times if, for example, you only wanted a store that saved to file every hour but another store that saved every few seconds. The filingsystem store allows you to change the write period.

I took a look, but I am lost.
What I have to do, that values in my global variable, won't be lost?
I am also confused how values were lost? Server (virtual machine) was not restarted.

You edit your settings.js file to enable global context variables to be saved to the filesystem.

Which system is node red running on?

Hey ghayne,
I am running node-red on ubuntu virtual machine.
I just checked settings.js.
Relevant part is this one:

// Context Storage
    // The following property can be used to enable context storage. The configuration
    // provided here will enable file-based context that flushes to disk every 30 seconds.
    // Refer to the documentation for further options: https://nodered.org/docs/api/context/
    //
    //contextStorage: {
    //    default: {
    //        module:"localfilesystem"
    //    },
    //},

    // The following property can be used to order the categories in the editor
    // palette. If a node's category is not in the list, the category will get
    // added to the end of the palette.
    // If not set, the following default order is used:
    //paletteCategories: ['subflows','flow','input','output','function','parser','social','mobile','storage','analysis','advanced'],

    // Configure the logging output

Should I simply decomment part contectstorage and leave it as is, or should I change anything?

Yes, just that bit! I would recommend that you make a copy of settings.js before you edit it, so that you can easily revert to it if you make a mistake while editing.

//contextStorage: {
    //    default: {
    //        module:"localfilesystem"
    //    },
    //},
contextStorage: {
        default: {
            module:"localfilesystem"
        },
    },
1 Like

ghayne,
I can confirm that after applying the changes, even after restart of the server values in the global context are still present. Thank you.
Regards,
Rok

1 Like

If you could mark my suggestion as the solution it might possibly help others who have the same problem, glad you got it working!

This is something I wrote you might find useful

1 Like