Cannot pull data from flow context when stored in filesystem

Hi there, first time poster and node-red novice here. Please forgive if my formatting, terminology, or information provided is wrong or isn’t what’s typically requested.

I can provide more information about what I’m trying to do, but my issue really distills down to where my context data is being stored, and I’m not sure if I’m just missing something basic.

I initially was doing everything with the default memory context store, but was having some issues that I think can be resolved with using the filesystem context store (I need the data to persist). So I edited the settings.js file by adding the following:

contextStorage: {
   default: "memory",
   memory: { module: 'memory' },
   file: { module: 'localfilesystem' }
}

So everything works well when I use a change node to set the flow data with ‘memory’ selected. I’m able to see the data was set in the context tab, and retrieve that data by using the $flowContext JSONata expression function, and use it for my desired purpose.

My issue is that this functionality breaks as soon as I select ‘file’ for the flow data storage. I’m still able to set the value fine, and I can still see that it’s been set in the context tab, and that it’s stored in ‘file,’ the local file system name given above. But it remains undefined when I try to call that data using the same $flowContext function.

Is there something that I’m missing here? I’m guessing that there’s notation that I need to apply to the $flowContext function to tell it to look to the flow data stored in the filesystem and not the flow data stored in memory. I just don’t know what that is.

Any help is much appreciated. If needed, I can post my present flow setup if that’s needed.

Any and all insight is appreciated in advance!

The $flowContext() can take a second optional argument, the context module name to use

$flowContext(string[, string])

$flowContext("name", "file")

If not set it will use default.

Thanks, E1cid!

That’s working perfectly in my little test bed. I’ll reach back out if it doesn’t carry over into my actual implementation (for my test bed, I was using an inject node to recall the data and pass along to a debug node; my actual intention is to recall the stored data to apply attributes in a Home Assistant call service node to return an RGB light to a prior state).

I’m loving Node-RED thus far, and really appreciate such a helpful introduction to the community. Much appreciated!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.