Cant get content value from container file

i changed the default settings.js to save variables in file system. i do it in this way

var value = 1;
context.set('value',value,"file");  // ✅ Store value in context

msg.payload = {
    "value": value
};
return msg;

i can see them also in docker container.

but when i try to get the value from file system i get undefined.

function node for getting value from file looks like this

var value = context.get("value","file"); //without file also didnt work
msg.payload = {
    "value": value
}  
return msg;

as returned msg.payload object i become;

msg.payload : Object

object

value: undefined

why cant i get the value which is saved in container?

Does it fetch the value if you do it without restarting node-red, or is it only after a restart that it fails?

Is this in the same function node as context is node based.

If you alter the function node the context for the node is deleted.

Try with flow context

It didnt work even i restart or not. The solution was using flow.get, flow.set instead of using content.get content.set

i dont know why but it worked with flow.get, flow.set. Thanks

As said
Context is node specific if you rewrite the function node the context is reset. You can only retrieve context from the function node that saved it, unless you alter that function node and redeploy.
Flow is flow specific, so is not reset when you alter the function node.
https://nodered.org/docs/user-guide/context

1 Like