# Template node - node.name

**URL:** <https://discourse.nodered.org/t/template-node-node-name/97690>\
**Category:** Feature Requests\
**Tags:** template\
**Created:** [19 June 2025 04:44 UTC](https://discourse.nodered.org/t/template-node-node-name/97690 "2025-06-19T04:44:34Z")\
**Posts on this page:** 17\
**Page:** 1

<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:** [19 June 2025 04:44 UTC](https://discourse.nodered.org/t/template-node-node-name/97690/1 "2025-06-19T04:44:34Z")

</div>

In a function node, one can use `node.name` to get the current node name, would it be possible to have this exposed/evaluated in a template node as well ?

eg.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/c/3c858315e4ffd3f5358885e86af54fef338ceacc.png)

---

<div class="post-metadata">

**Author:** ![omrid](https://avatars.discourse-cdn.com/v4/letter/o/77aa72/32.png) [@omrid](https://discourse.nodered.org/u/omrid)\
**Post date:** [19 June 2025 12:38 UTC](https://discourse.nodered.org/t/template-node-node-name/97690/2 "2025-06-19T12:38:38Z")

</div>

All the node's config parameters are available in the template node's `props` object.  
for example:

```auto
this.send(this.props.name); // outputs the node name

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [19 June 2025 12:54 UTC](https://discourse.nodered.org/t/template-node-node-name/97690/3 "2025-06-19T12:54:32Z")

</div>

Omri, the OP is asking about the Node-RED core `template` (not ui-template)

@bakman2 You already have access to the same ENV VARs the function node does:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fca7a2efdc19f6d7b01a4aa0450176608f9a3102.png)

```bash
This is the payload: {{payload}} 

env.NR_FLOW_NAME: {{env.NR_FLOW_NAME}}

env.NR_GROUP_NAME: {{env.NR_GROUP_NAME}}

env.NR_NODE_NAME: {{env.NR_NODE_NAME}}

```

---

<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:** [19 June 2025 14:49 UTC](https://discourse.nodered.org/t/template-node-node-name/97690/4 "2025-06-19T14:49:18Z")

</div>

😲 when did that happen?! I must have been asleep when that was introduced. 😄

Also, is there a way to find all of the `env` variables? As I note that they are not included in `process.env`.

THere also seems to be a bug in the `env.get()` function. If you try to use `env.NR_NODE_NAME` in a function node and the node does not have a name set, it throws an error and so stops the function from executing. It should not do that, having an undefined name is perfectly valid and not an error condition.

That is true for other env variables such as group name and id as well so presumably it is a problem with the get function.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/c/bcad8bb6f7e5f328ae0f57a95af5d66a866d0a29.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [19 June 2025 15:21 UTC](https://discourse.nodered.org/t/template-node-node-name/97690/5 "2025-06-19T15:21:32Z")

</div>

works fine here  
 ![chrome_UULNEJCUgu](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/8/a82f969b66467693da23a96dbd1bc60156e3e859.gif)

---

<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:** [19 June 2025 15:24 UTC](https://discourse.nodered.org/t/template-node-node-name/97690/6 "2025-06-19T15:24:22Z")

</div>

Try this. BTW, I'm using the Beta version of Node-RED

```js
// msg.payload1 = process.env
msg.payload = {
    NR_NODE_ID: env.NR_NODE_ID // - the ID of the node
    // NR_NODE_NAME: env.NR_NODE_NAME // - the Name of the node
    NR_NODE_PATH: env.NR_NODE_PATH // - the Path of the node. This represents a node’s position in a flow. It is / delimited IDs of the flow, enclosing subflows, and the node.
    // NR_GROUP_ID: env.NR_GROUP_ID // - the ID of the containing group
    // NR_GROUP_NAME: env.NR_GROUP_NAME // - the Name of the containing group
    // NR_FLOW_ID: env.NR_FLOW_ID // - the ID of the flow the node is on
    // NR_FLOW_NAME: env.NR_FLOW_NAME // - the Name of the flow the node is on
    // NR_SUBFLOW_NAME: env.NR_SUBFLOW_NAME // - the Name of the containing subflow instance node (since Node-RED 3.1)
    // NR_SUBFLOW_ID: env.NR_SUBFLOW_ID // - the ID of the containing subflow instance node (since Node-RED 3.1)
    // NR_SUBFLOW_PATH: env.NR_SUBFLOW_PATH // - the Path of the containing subflow instance node (since Node-RED 3.1)
}
return msg;

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [19 June 2025 15:26 UTC](https://discourse.nodered.org/t/template-node-node-name/97690/7 "2025-06-19T15:26:08Z")

</div>

but that is not how env is supposed to be used.

From online docs: [Writing Functions : Node-RED](https://nodered.org/docs/user-guide/writing-functions#env)

> `env`
> 
> - `env.get(..)` : get an environment variable

And the function signature:

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

---

<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:** [19 June 2025 15:26 UTC](https://discourse.nodered.org/t/template-node-node-name/97690/8 "2025-06-19T15:26:35Z")

</div>

This might be another bug in the beta as well? Note the lack of Monaco icons:

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

BTW, this is a clean, standard global install of Node-RED, not my usual install.

---

<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:** [19 June 2025 15:28 UTC](https://discourse.nodered.org/t/template-node-node-name/97690/9 "2025-06-19T15:28:27Z")

</div>

And this also fails:

```js
// msg.payload1 = process.env
msg.payload = {
    NR_NODE_ID: env.get('NR_NODE_ID') // - the ID of the node
    NR_NODE_NAME: env.get('NR_NODE_NAME') // - the Name of the node
    // NR_NODE_PATH: env.get('NR_NODE_PATH') // - the Path of the node. This represents a node’s position in a flow. It is / delimited IDs of the flow, enclosing subflows, and the node.
    // NR_GROUP_ID: env.get('NR_GROUP_ID') // - the ID of the containing group
    // NR_GROUP_NAME: env.get('NR_GROUP_NAME') // - the Name of the containing group
    // NR_FLOW_ID: env.get('NR_FLOW_ID') // - the ID of the flow the node is on
    // NR_FLOW_NAME: env.get('NR_FLOW_NAME') // - the Name of the flow the node is on
    // NR_SUBFLOW_NAME: env.get('NR_SUBFLOW_NAME') // - the Name of the containing subflow instance node (since Node-RED 3.1)
    // NR_SUBFLOW_ID: env.get('NR_SUBFLOW_ID') // - the ID of the containing subflow instance node (since Node-RED 3.1)
    // NR_SUBFLOW_PATH: env.get('NR_SUBFLOW_PATH') // - the Path of the containing subflow instance node (since Node-RED 3.1)
}
return msg;

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [19 June 2025 15:29 UTC](https://discourse.nodered.org/t/template-node-node-name/97690/10 "2025-06-19T15:29:01Z")

</div>

> [@TotallyInformation](#):
>
> And this also fails:
> 
> ```auto
> // msg.payload1 = process.env
> msg.payload = {
> NR_NODE_ID: env.get('NR_NODE_ID') // - the ID of the node
> NR_NODE_NAME: env.get('NR_NODE_NAME') //
> 
> ```

There is no comma after `NR_NODE_ID: env.get('NR_NODE_ID')`

---

<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:** [19 June 2025 15:31 UTC](https://discourse.nodered.org/t/template-node-node-name/97690/11 "2025-06-19T15:31:51Z")

</div>

> [@Steve-Mcl](#):
>
> but that is not how env is supposed to be used.

Kind of goes against JavaScript standards where a get function should be transparent. However.

In the beta, I am not getting the function signature in Monaco.

Oh, wait - no, I wondered if it was somehow set to ACE but no, it is set to Monaco.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [19 June 2025 15:32 UTC](https://discourse.nodered.org/t/template-node-node-name/97690/12 "2025-06-19T15:32:37Z")

</div>

> [@TotallyInformation](#):
>
> In the beta, I am not getting the function signature in Monaco.

Not seeing that at all - I JUST installed node-red@next

![chrome_z8keszmquR](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/0/00b8132ec1cacf49b9fbc50283c88e88dbfa883e.gif)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [19 June 2025 15:33 UTC](https://discourse.nodered.org/t/template-node-node-name/97690/13 "2025-06-19T15:33:54Z")

</div>

> [@TotallyInformation](#):
>
> Kind of goes against JavaScript standards where a get function should be transparent

Not a standard I've read? Perhaps you are thinking of how getter and setters props are written? (in this case `get` is a method)

---

<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:** [19 June 2025 15:46 UTC](https://discourse.nodered.org/t/template-node-node-name/97690/14 "2025-06-19T15:46:13Z")

</div>

> [@Steve-Mcl](#):
>
> There is no comma after `NR_NODE_ID: env.get('NR_NODE_ID')`

Darn it! I'm on an annoying little MS Surface pro, not my home setup! But also annoying that while the syntax error did show in the NR log, it did not show in NR Admin.

Thanks for correcting that, this now works:

```js
// msg.payload1 = process.env
msg.payload = {
    NR_NODE_ID: env.get('NR_NODE_ID'), // - the ID of the node
    NR_NODE_NAME: env.get('NR_NODE_NAME'), // - the Name of the node
    NR_NODE_PATH: env.get('NR_NODE_PATH'), // - the Path of the node. This represents a node’s position in a flow. It is / delimited IDs of the flow, enclosing subflows, and the node.
    NR_GROUP_ID: env.get('NR_GROUP_ID'), // - the ID of the containing group
    NR_GROUP_NAME: env.get('NR_GROUP_NAME'), // - the Name of the containing group
    NR_FLOW_ID: env.get('NR_FLOW_ID'), // - the ID of the flow the node is on
    NR_FLOW_NAME: env.get('NR_FLOW_NAME'), // - the Name of the flow the node is on
    NR_SUBFLOW_NAME: env.get('NR_SUBFLOW_NAME'), // - the Name of the containing subflow instance node (since Node-RED 3.1)
    NR_SUBFLOW_ID: env.get('NR_SUBFLOW_ID'), // - the ID of the containing subflow instance node (since Node-RED 3.1)
    NR_SUBFLOW_PATH: env.get('NR_SUBFLOW_PATH'), // - the Path of the containing subflow instance node (since Node-RED 3.1)
}
return msg;

```

> [@Steve-Mcl](#):
>
> Not seeing that at all - I JUST installed node-red@next

Are you able to install NR with a `--production` flag, not sure if that is causing it. I tend to do that without thinking.

> [@Steve-Mcl](#):
>
> Not a standard I've read? Perhaps you are thinking of how getter and setters props are written? (in this case `get` is a method)

Might just be that I have had to get up close and personal with a lot of getters/setters recently and expect that a `something.get('fred')` === `something.fred` since this is an increasingly common thing to do.

---

<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:** [19 June 2025 15:47 UTC](https://discourse.nodered.org/t/template-node-node-name/97690/15 "2025-06-19T15:47:06Z")

</div>

> [@Steve-Mcl](#):
>
> `env.NR_FLOW_NAME: {{env.NR_FLOW_NAME}}`

And, to be fair - that is how you wrote it in your original post! 😄 But yes, I realise that is a different case - however, it is very confusing for users.

---

<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:** [20 June 2025 05:59 UTC](https://discourse.nodered.org/t/template-node-node-name/97690/16 "2025-06-20T05:59:00Z")

</div>

This works for me, thanks. I am not able to close this topic (?). Perhaps someone can mark it ?

---

<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:** [20 June 2025 08:37 UTC](https://discourse.nodered.org/t/template-node-node-name/97690/17 "2025-06-20T08:37:46Z")

</div>


