# \`template\` node. Not understanding all that is written

**URL:** <https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670>\
**Category:** General\
**Created:** [28 December 2019 06:12 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670 "2019-12-28T06:12:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 December 2019 06:12 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/1 "2019-12-28T06:12:52Z")

</div>

Ok, a recent conversation I was in mentioned the `template` node.

After that, I looked at the node's `info`.

I don't understand:  
`It is possible to use a property from the flow context or global context. Just use {{flow.name}} or {{global.name}}, or for persistable store store use {{flow[store].name}} or {{global[store].name}}. `

`context` is local to that node, so can't really be used in this case.  
`flow` the variable is limited to that/this flow.  
`global` the variable is access by all flows.

So what is this `{{flow[store].name}}` mean?

And why the changed syntax?  
I thought it was `flow.set( )` or `flow.get( )`

Please - someone.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [28 December 2019 06:33 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/2 "2019-12-28T06:33:08Z")

</div>

`flow.set(...)` is javascript.  
This is not a function node and does not use javascript:

> Sets a property based on the provided template.  
> By default this uses the _[mustache](http://mustache.github.io/mustache.5.html)_ format, but this can be switched off if required.

The node is used to create a new payload with the content provided in the template. The mustache format is used to expand the properties.

In this case: `flow.get("bla")` becomes `{{flow.bla}}` in the template node. The `store` option is used to specify the store configured in settings.js (which will default to `default` if not specified) ie you could read it from the memory store or from disk, both depending on how it is configured in settings.js.

You don't set variables in the template node, only read (to create a custom payload)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 December 2019 06:38 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/3 "2019-12-28T06:38:53Z")

</div>

I apologise. I _confused_ JS with _mustache_ format.

I still don't get/understand

> [@bakman2](#):
>
> The `store` option is used to specify the store configured in settings.js

But I'm not that smart.  
Because I haven't really used the node much, I may not have yet needed to understand the uses it offers.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [28 December 2019 06:49 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/4 "2019-12-28T06:49:55Z")

</div>

Do you store you variables on disk or only in memory ?  
You can set it to store it on both disk and memory in settings.js

Example, my settings.js:

```auto
contextStorage: {
    default: {
        module:"localfilesystem"
    },
},

```

The `default` is the store.  
You can specify additional stores ([see documentation](https://nodered.org/docs/user-guide/context#saving-context-data-to-the-file-system))

In normal situations you will not use this option.

The template node can be used for many things, but let's say you receive payload from a weather station

```auto
{"payload":{
"temp":23,
"humidity":64,
"rain":0
}}

```

With the template node, you could (cleanly) write a weather report:

```auto
Today's temperature is {{payload.temp}}C, {{payload.humidity}}% humidity and {{payload.rain}}mm rain.

```

There is no logic, just expanded text.  
And yes you can do the same with a function node (or jsonata) but a template node can make it more readable.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 December 2019 07:00 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/5 "2019-12-28T07:00:39Z")

</div>

Thanks.

Sorry, but my _parsing systems_ are being difficult for me just now.

> [@bakman2](#):
>
> Do you store you variables on disk or only in memory ?  
> The `default` is the store.

Eeeeewww... There is disk or memmory. Declared. Then the default is **store**.

Error. Type not declared.

So:

```auto
context.Storage:{
    default:{
       modoule:"localfilesystem"
    },
},

```

Ok. I get that. It stores context to the disk - or so I take it. Localfilesystem.

That is the default yes? Looking through my `settings.js` file I am not finding it. (Shrug)

Thanks though for the example of the `template` node. I will have to keep it in mind for future use.

(This is nothing against you. It is I am just showing my problems understanding what is written.)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [28 December 2019 07:02 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/6 "2019-12-28T07:02:58Z")

</div>

> [@Trying\_to\_learn](#):
>
> context.Storage:{ default:{

Look at the word "default", that is the default, not "store"

You can configure it like stated in the documentation:

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

```

So you if you want to specify a (configured) store you can choose (thus: default, file, memoryOnly)

And note the typo

```auto
context.Storage:{
    default:{
      --> modoule:"localfilesystem"
    },
},

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 December 2019 07:11 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/7 "2019-12-28T07:11:10Z")

</div>

Ok...

I haven't changed it from _the default_.

But in saying that....  
This is what I see:

```auto
me@me-desktop:~/.node-red$ cat settings.js | grep context
    // It is accessed as context.global.
    // context.global.os
me@me-desktop:~/.node-red$ 

```

So I can't find/see `context.Storage` in the `settings.js` file.  
(Or `contextStorage`)

Sorry. I'm a bit stressed. Please understand I am not angry with your help.  
I am just really confused.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [28 December 2019 07:49 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/8 "2019-12-28T07:49:30Z")

</div>

And your node-red version is?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 December 2019 07:50 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/9 "2019-12-28T07:50:33Z")

</div>

Node red version:

1.0.3

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [28 December 2019 07:55 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/10 "2019-12-28T07:55:41Z")

</div>

I don't understand how as it is part of the settings file.  
instead of  
`cat settings.js | grep context`  
can you do a  
`cat settings.js | grep -i context`

The `-i` implies `ignore case` making it case insenstive (little tip to always use that)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 December 2019 07:57 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/11 "2019-12-28T07:57:24Z")

</div>

> [@bakman2](#):
>
> cat settings.js | grep -i context

```auto
me@me-desktop:~/.node-red$ cat settings.js | grep -i context
    // It is accessed as context.global.
    // functionGlobalContext: { os:require('os') }
    // context.global.os
    functionGlobalContext: {
me@me-desktop:~/.node-red$ 

```

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [28 December 2019 07:59 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/12 "2019-12-28T07:59:50Z")

</div>

If you are sure that you are checking it on the correct host with version 1.0.3 then our node-red hero's can perhaps explain it as this is beyond me.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 December 2019 08:03 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/13 "2019-12-28T08:03:24Z")

</div>

Just so there is no confusion:

```auto
me@me-desktop:~/.node-red$ cat settings.js | grep context
    // It is accessed as context.global.
    // context.global.os
me@me-desktop:~/.node-red$ cat settings.js | grep -i context
    // It is accessed as context.global.
    // functionGlobalContext: { os:require('os') }
    // context.global.os
    functionGlobalContext: {
me@me-desktop:~/.node-red$ man grep
me@me-desktop:~/.node-red$ ifconfig
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
        inet 192.168.0.6 netmask 255.255.255.0 broadcast 192.168.0.255

(some stuff cut out for brevity)

me@me-desktop:~/.node-red$ 

```

Note IP address

 ![Screenshot from 2019-12-28 19-01-03](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/99730946e18ad26ed4f8f3027bce1fdf4e925111.png)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [28 December 2019 08:20 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/14 "2019-12-28T08:20:34Z")

</div>

As long as '192.168.0.6' is the same machine as 'me@me-desktop'

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 December 2019 08:21 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/15 "2019-12-28T08:21:19Z")

</div>

That's why I posted the commands with the `ifconfig` output.

---

<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:** [28 December 2019 08:21 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/16 "2019-12-28T08:21:44Z")

</div>

If you have upgraded from older versions then your settings file will not be overwritten with a new one, so new options may not be there

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [28 December 2019 08:25 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/17 "2019-12-28T08:25:43Z")

</div>

Ah sorry it's early here 😉  
But @dceejay explained where the difference comes from

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 December 2019 08:30 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/18 "2019-12-28T08:30:10Z")

</div>

Ok, no problem, I guess.

But to me that is a "red flag" (excuse the term) for me as:  
if I upgraded and new features were added. Shouldn't their configs be _forced_ into the settings.js file?

Excluding them causes confusion for people like me.

Anyway, I'm still not getting why the `template` node needs to STORE settings.  
Or more so:  
`{{flow[store].name}}`

Still not getting it.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [28 December 2019 08:44 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/19 "2019-12-28T08:44:54Z")

</div>

> Anyway, I'm still not getting why the `template` node needs to STORE settings.

it is not "STORING", it is reading the store, which store ? The one you specify.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 December 2019 08:46 UTC](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670/20 "2019-12-28T08:46:16Z")

</div>

Ok. I may have to go away and have a re-think about it.

[Next page](https://discourse.nodered.org/t/template-node-not-understanding-all-that-is-written/19670.md?page=2)
