# Using simpler globar variables \`RED.f.myVar\`

**URL:** <https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179>\
**Category:** Core Development\
**Tags:** suggestion\
**Created:** [3 June 2026 00:40 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179 "2026-06-03T00:40:32Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![PizzaProgram](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pizzaprogram/32/19431_2.png) [@PizzaProgram](https://discourse.nodered.org/u/PizzaProgram)\
**Post date:** [3 June 2026 00:40 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/1 "2026-06-03T00:40:32Z")

</div>

I'm currently a bit frustrated why it has to be sooooo complicated to use always [these](https://nodered.org/docs/user-guide/writing-functions#storing-data) `flow.get() .set()` methods to simply store a variable in memory?

I know I can make my own "utility functions", but still I have to define that in every each function to be able to access.

## So the million $ question:

- Why not pre-define two ?

1. `RED.global` = `RED.g`
2. `RED.flow` = `RED.f`

(`RED.g` and `RED.f` are short-form aliases.)  
So anybody could simply use them everywhere just list this:

```js
RED.f.myCounter += RED.g.myArray[0].value;

```

and that's all!  
And for everything else (like context store on HDD, etc) everyone could still use the old methods.

# Edit:

Using simply `flow.myVar`, and `global.myVar` would be the best, but it **does not work** , because it's only keeping the value inside each Node separately.

### Maybe it's a bug?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [3 June 2026 07:02 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/2 "2026-06-03T07:02:10Z")

</div>

Because we want a single api for context so the user doesn’t need to have to think/know about where they want to store things, and that can be changed (in settings.js) at any time without breaking the flow.

Also flow.myvar (and global.myvar ) - which are memory only -,should still work in function nodes but won’t show up in the context sidebar or other nodes

Do I get my million $ ?

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [3 June 2026 07:25 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/3 "2026-06-03T07:25:20Z")

</div>

> [@PizzaProgram](#):
>
> 1. `RED.global` = `RED.g`
> 2. `RED.flow` = `RED.f`

Maybe I'm being a bit thick but surely it should be written as...

```auto
RED.g = RED.global;
RED.f = RED.flow;

```

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [3 June 2026 08:03 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/4 "2026-06-03T08:03:57Z")

</div>

> [@PizzaProgram](#):
>
> I'm currently a bit frustrated why it has to be sooooo complicated to use always [these](https://nodered.org/docs/user-guide/writing-functions#storing-data) `flow.get() .set()` methods to simply store a variable in memory?

Complex? `const myvar = flow.get('myvar')` is complex? Much more complex than `const myvar = flow.myvar`?

You could, of course, use change nodes. One before your function node to get the data and add it to an incoming message and one after to write the update data back. Though that seems a lot more complex.

You could always also set a couple of snippets of code into the library for easy access.

---

<div class="post-metadata">

**Author:** ![mudwalker](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mudwalker](https://discourse.nodered.org/u/mudwalker)\
**Post date:** [3 June 2026 09:25 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/5 "2026-06-03T09:25:57Z")

</div>

Isn't `flow.set() get()` standard JS?

I am not sure about lower (/higher) level programming, but I for one, would really like to keep my JS standard and not wonder what `RED.g RED,f` are in an example flow.

Maybe I am missing the point?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [3 June 2026 09:30 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/6 "2026-06-03T09:30:18Z")

</div>

Agree. If anything `const fg = flow.get` and similar if you are using it a lot in a function node. And if you _are_ using these things a "lot" in a function node, you may want to take a step back for a minute and think about whether you are doing things the best way.

---

<div class="post-metadata">

**Author:** ![PizzaProgram](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pizzaprogram/32/19431_2.png) [@PizzaProgram](https://discourse.nodered.org/u/PizzaProgram)\
**Post date:** [3 June 2026 09:53 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/7 "2026-06-03T09:53:59Z")

</div>

> [@TotallyInformation](#):
>
> Complex? `const myvar = flow.get('myvar')` is complex? Much more complex than `const myvar = flow.myvar`?

Yes, it is.

```js
let myvar = flow.get('mySpecialVar');
myvar = 5;
flow.set('mySpecalVar', myvar); // error already happend

```

With my idea:

```js
RED.f.mySpecialVar = 5;

```

---

<div class="post-metadata">

**Author:** ![PizzaProgram](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pizzaprogram/32/19431_2.png) [@PizzaProgram](https://discourse.nodered.org/u/PizzaProgram)\
**Post date:** [3 June 2026 10:01 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/8 "2026-06-03T10:01:51Z")

</div>

> [@dynamicdave](#):
>
> Maybe I'm being a bit thick but surely it should be written as...
> 
> ```auto
> RED.g = RED.global;
> RED.f = RED.flow;
> 
> ```

Yes, it looks nicer 😉  
They would work as alias, so both could be used the same way.  
If anyone can thing of an even shorted form, that can be easily memorised, share it here!  
eg. `NRV` = NodeRed Variable

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [3 June 2026 11:01 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/9 "2026-06-03T11:01:42Z")

</div>

Just to point out that if mySpecialVar is an object, then you do not need to use flow.set() to update key values stored in it.

This is valid in a function node, and updates the counter stored in flow context.

```auto
node.warn(flow.get('RED').counter ++)

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/1/91b256a56e2744c337a72197e63d372edbbfe077.png)

```auto
[{"id":"2735b59096ed3aa4","type":"function","z":"790f697c022493af","name":"function 19","func":"node.warn(flow.get('RED').counter ++)","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1250,"y":240,"wires":[[]]},{"id":"89a8cf55016f77c4","type":"inject","z":"790f697c022493af","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1080,"y":240,"wires":[["2735b59096ed3aa4"]]},{"id":"b410e9a77bfee940","type":"inject","z":"790f697c022493af","name":"init","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1070,"y":80,"wires":[["09fad47bf63d1869"]]},{"id":"09fad47bf63d1869","type":"change","z":"790f697c022493af","name":"Create flow.myobject","rules":[{"t":"set","p":"RED","pt":"flow","to":"{\"counter\":0}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":1260,"y":80,"wires":[[]]}]

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [3 June 2026 11:06 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/10 "2026-06-03T11:06:20Z")

</div>

> [@jbudd](#):
>
> This is valid in a function node, and updates the counter stored in flow context.

But only for in-memory context stores. If you're enabled File-based persistence, then not calling `set` will mean the value doesn't get saved as you might expect and will revert if you restart NR.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [3 June 2026 11:20 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/11 "2026-06-03T11:20:11Z")

</div>

> [@PizzaProgram](#):
>
> With my idea:
> 
> ```auto
> RED.f.mySpecialVar = 5;
> 
> ```

Nope! That is incorrect. Partially anyway. While that does work for in-memory variables right now, it might not work for other variable libraries and might not work in the future anyway. It is dangerous and fragile.

Best to think of context variables as an API with access only via get and set. Your future self will likely thank you greatly. 😃

If you really wanted to simplify the coding, we would need the core to replace the current libraries with a JavaScript proxy. That would allow the get/set to be hidden within the proxy.

---

<div class="post-metadata">

**Author:** ![PizzaProgram](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pizzaprogram/32/19431_2.png) [@PizzaProgram](https://discourse.nodered.org/u/PizzaProgram)\
**Post date:** [3 June 2026 12:37 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/12 "2026-06-03T12:37:00Z")

</div>

@jbudd Wow! Actually this is a great idea! 👍

Not perfect, but +1 step easier. (No need to use `flow.set()`, a few lines less of coding).  
I've never thought that a flaw of object-deep-copy problem can be a benefit too!

### Basically we are:

1. loading only the reference (pointer) of the object at the beginning,
2. and modifying only the sub-values of it,
3. this way we do not have to "save it" back.

- Right?

* * *

This is easierst method, how my idea would be doable programmatically inside the core.  
So basically +2 lines in the source would allow to everyone to use global + flow variables without get() set().

It does not need to begin with `RED. ` . Could be `_GV` for globalValues, `_FV` for flowValues.

* * *

What I still not understand is:

- if it is enough to load=get() the object reference point,
- and if I put the declaration part of it to the "OnStart" tab of the node,  
`let c = flow.get('RED');`
- why is it not working than? `node.warn(c.counter ++);`

```json
[{"id":"9147025004dc8078","type":"function","z":"163bd37ac7d1c01c","name":"function 1","func":"node.warn(c.counter ++);","outputs":1,"timeout":0,"noerr":0,"initialize":"let c = flow.get('RED');","finalize":"","libs":[],"x":360,"y":280,"wires":[[]]},{"id":"9ec33294fae26402","type":"inject","z":"163bd37ac7d1c01c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":180,"y":280,"wires":[["9147025004dc8078"]]}]

```

* * *

### @jbudd Note:

`RED` is a global reserved word in NR. We should not use it in examples as sub-variables, because it may confuse users visiting later this topic.

* * *

@knolleary Yes, thanks, we know that! I've explicitly said at the beginning:

- Store in MEMORY ONLY.
- Only as long we restart the flow / NR.
- No need to write temporary variables to disc!

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [3 June 2026 12:45 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/13 "2026-06-03T12:45:53Z")

</div>

I know you know and I know you said it. The dangerous part comes when others read this thread and don't appreciate that subtle yet very important reason for `set` being used.

You are free to do whatever works for you.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [3 June 2026 12:46 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/14 "2026-06-03T12:46:33Z")

</div>

> [@PizzaProgram](#):
>
> ### @budd Note:
> 
> `RED` is a global reserved word in NR. We should not use it in examples as sub-variables, because it may confuse users visiting later this topic.

Point taken, thanks.

Actually I would say that updating an object, in context or anywhere else, without explicitly saving it is likely to confuse anyone apart from the original coder who has to maintain the code, and therefore we should not do it.

If I were to implement a counter in context I would use

```auto
const iterationCounter = context.get('iterationCounter') +1 || 1
context.set('iterationCounter', iterationCounter)

...
node.warn("You have run this " + iterationCounter + " times")

// And if I want to use the counter later in the flow, attach it to the message
msg.iterationCounter = iterationCounter

```

---

<div class="post-metadata">

**Author:** ![PizzaProgram](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pizzaprogram/32/19431_2.png) [@PizzaProgram](https://discourse.nodered.org/u/PizzaProgram)\
**Post date:** [3 June 2026 13:05 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/15 "2026-06-03T13:05:27Z")

</div>

> [@knolleary](#):
>
> You are free to do whatever works for you.

Yes, thanks, but I'm not sure where to place it into Node-red **core** code,  
and even if I would find a good place for it in the source,  
I'm not sure You guys would **accept my commit?**

That's why I'd like to discuss it first here.  
_(But it seems everyone is against my idea to simplify usage of global temp.variables.)_

## OFF

I still remember how much time it took me to learn about context variables at the first time, when I've started to use NodeRed years ago.  
Also there are many many topics asking about the same simple question:

- how to use global variables that can be passed on to other nodes,
- which are not connected to each other
- and would confuse everyone if they would be!

> [@jbudd](#):
>
> ```auto
> // And if I want to use the counter later in the flow, attach it to the message
> msg.iterationCounter = iterationCounter
> 
> ```

Yes, that's the default way, if it is possible.  
But life is more complicated than 1 simple line of flow ...  
_(for example: keeping count+lastAccess of all MQTT clients, who connected before.)_

---

<div class="post-metadata">

**Author:** ![PizzaProgram](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pizzaprogram/32/19431_2.png) [@PizzaProgram](https://discourse.nodered.org/u/PizzaProgram)\
**Post date:** [3 June 2026 13:06 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/16 "2026-06-03T13:06:22Z")

</div>

> [@PizzaProgram](#):
>
> - why is it not working than? `node.warn(c.counter ++);`

Can somebody answer me that please?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [3 June 2026 13:21 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/17 "2026-06-03T13:21:11Z")

</div>

Maybe I've missed your proposal. You want `RED.f` and `RED.g` to exist as shorthands for `flow` and `global` ? Or something else?

---

<div class="post-metadata">

**Author:** ![PizzaProgram](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pizzaprogram/32/19431_2.png) [@PizzaProgram](https://discourse.nodered.org/u/PizzaProgram)\
**Post date:** [3 June 2026 13:33 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/18 "2026-06-03T13:33:08Z")

</div>

No, not shorthands.  
Yes, something else:

- pre-existing global variable containers.

`RED.g = {};` would be created when NR starts.  
`RED.f = {};` would be created for each flow. (Separately).

This way new users (and we) had two, easy-useable variables-trunc defined, which can be used for any sub-variable.  
How you name it:  
`RED.f` or `_FV` or `flowVar`, I do not care, as long it is documented [here](https://nodered.org/docs/user-guide/context) and [here](https://nodered.org/docs/writing-functions#storing-data).

---

<div class="post-metadata">

**Author:** ![PizzaProgram](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pizzaprogram/32/19431_2.png) [@PizzaProgram](https://discourse.nodered.org/u/PizzaProgram)\
**Post date:** [3 June 2026 13:39 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/19 "2026-06-03T13:39:37Z")

</div>

> [@PizzaProgram](#):
>
> What I still not understand is:
> 
> - if it is enough to load=get() the object reference point,
> - and if I put the declaration part of it to the "OnStart" tab of the node,  
> `let c = flow.get('RED');`
> - why is it not working than? `node.warn(c.counter ++);`

# I have found the problem:

Using `let ...` or `var ...` **is bad** at "On Start" tab !  
This one works:

```js
c = flow.get('RED'); // good :-)

```

But WHY ?  
I've thought the 'On Start' tab context is the same / parent of "on Message"...

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [3 June 2026 13:41 UTC](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179/20 "2026-06-03T13:41:36Z")

</div>

We aren't going to introduce another way to use context that doesn't quite work the same as other ways of using context.

If you really want to, you can just use `flow.myVariable = "hello"` - no need for us to introduce more globals.

[Next page](https://discourse.nodered.org/t/using-simpler-globar-variables-red-f-myvar/101179.md?page=2)
