# \[Proposal\] Make node name accessible as environment variable

**URL:** <https://discourse.nodered.org/t/proposal-make-node-name-accessible-as-environment-variable/56587>\
**Category:** Core Development\
**Created:** [13 January 2022 11:57 UTC](https://discourse.nodered.org/t/proposal-make-node-name-accessible-as-environment-variable/56587 "2022-01-13T11:57:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nisiyama](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nisiyama/32/85_2.png) [@nisiyama](https://discourse.nodered.org/u/nisiyama)\
**Post date:** [13 January 2022 11:57 UTC](https://discourse.nodered.org/t/proposal-make-node-name-accessible-as-environment-variable/56587/1 "2022-01-13T11:57:38Z")

</div>

As we can see in the following posts, I think it makes sense to be able to refer to the node name because each node has a name attribute and many nodes have meaningful names on the flow.

- [Access subflow name like an environment variable?](https://discourse.nodered.org/t/access-subflow-name-like-an-environment-variable/17061)
- [Proposal: expose subflow id and name for all its nodes](https://discourse.nodered.org/t/proposal-expose-subflow-id-and-name-for-all-its-nodes/663)

So, I would like to propose the following extension to environment variable.

**Proposal**

- References to `_NODE_NAME_` environment variable are replaced with the value of the node's name property.

---

<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:** [13 January 2022 16:43 UTC](https://discourse.nodered.org/t/proposal-make-node-name-accessible-as-environment-variable/56587/2 "2022-01-13T16:43:38Z")

</div>

I wonder if there is a set of standard properties that could be exposed in this way.

- name
- id
- path

The only bit I'm less sure on is the format of the env var. We tend to prefix properties with `_` if they are more internal and not necessarily meant for general use.

I would suggest `NODE_NAME` `NODE_ID` and `NODE_PATH` ?

Having written that out, `NODE_PATH` is a well-known environment variable already - not that I'd expect a NR flow to ever want to make use of it. But it could cause confusion.

---

<div class="post-metadata">

**Author:** ![nisiyama](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nisiyama/32/85_2.png) [@nisiyama](https://discourse.nodered.org/u/nisiyama)\
**Post date:** [14 January 2022 00:04 UTC](https://discourse.nodered.org/t/proposal-make-node-name-accessible-as-environment-variable/56587/3 "2022-01-14T00:04:45Z")

</div>

`id` is an additional candidate as environment variable.  
I used `_` as prefix because I was afraid of collision with the existing variable name, but it is okay to omit `_` according to the policy.

Regarding path, as it is still in the design discussion stage, I think it is better to discuss it together with that design. From the `NODE_PATH` environment variable you pointed out, I come to a little concerns that the name `path` may be mistaken as the directory path where the node is installed.

---

<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:** [14 January 2022 00:12 UTC](https://discourse.nodered.org/t/proposal-make-node-name-accessible-as-environment-variable/56587/4 "2022-01-14T00:12:51Z")

</div>

Good point about the `path` name.

As you know (but for other readers' benefit) it is the name of an internal property used to identify exactly where a node exists in a flow (such as inside nested subflows). And we have a separate discussion over exposing that more formally as a node property.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [15 March 2022 00:13 UTC](https://discourse.nodered.org/t/proposal-make-node-name-accessible-as-environment-variable/56587/5 "2022-03-15T00:13:40Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
