Reputation: 559
We are working on refactoring our node-red flows. So I was trying to find a way to clear our context without having to restart node-red every time.
The thing is we are not using the conventional global.get()
and global.set()
to access the global context; we use a context.global
variable, for which I cant find any reference in documentation.
So to set a new global variable we go context.global.var1 = "value"
instead of global.set('var1','value')
;
And to get the value we go var thisvalue = context.global.var1
instead of var thisvalue = global.get('var1')
.
Also note that these two variables are not stored in the same place, context.global
is not displayed in the Context Data Tab. And I cannot get its values with the global.get method.
So what is the difference between these two methods, and how could I clear this context.global
, noting that I tried these methods:
context.global= new Object();
context.global= {};
context.global={'empty','empty'};
context.global=null;
Additional Info: we use version v0.20.3 of node-red
Thank you
Upvotes: 1
Views: 5123
Reputation: 59751
Using context.global.var
is deprecated (hence why it has been removed from the doc) in favour global.set()
, flow.set()
or context.set()
because this allows the use of storage plugins to make context persistent across restarts.
Storage plugins also allow you to use things this redis to share the context between multiple instances of Node-RED.
If you want to clear values in the context you need to set them to undefined
The other option is to write your own storage plugin that you can choose to clear how ever you want (based on what ever you use as the backing store)
Upvotes: 3