You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Environment variables can be set at the flow or group level. This is done in the appropriate tab in the edit dialog for the flow or group.
86
90
91
+
### Accessing nested environment variables
92
+
93
+
When accessing an environment variable in a subflow, Node-RED will search the
94
+
subflow properties, then the flow containing the subflow (which could be a subflow
95
+
itself).
96
+
97
+
In some cases it is useful to access the 'parent' levels environment variables
98
+
without reference the 'local' value. This can be achieved by prefixing the
99
+
variable name with `$parent.`.
100
+
101
+
87
102
### Running as a service
103
+
88
104
When Node-RED is running as a service having been installed using the provided [script](https://nodered.org/docs/getting-started/raspberrypi), it will not have access to environment variables that are defined only in the calling process. In this instance, environment variables can be defined in the settings file by adding:
89
-
````
90
-
process.env.FOO= 'World';
91
-
````
105
+
106
+
```
107
+
process.env.FOO='World';
108
+
```
109
+
92
110
placed outside the `module.exports` section. Alternatively, variables can be defined as part of the `systemd` service by placing statements of the form
111
+
93
112
```
94
113
ENV_VAR='foobar'
95
-
````
96
-
in a file named `environment` in the Node-RED user directory, `~/.node-red`.
114
+
```
115
+
in a file named `environment` within the Node-RED user directory, `~/.node-red`.
116
+
117
+
118
+
### Built-In Environment Variables
119
+
120
+
*Since Node-RED 2.2*
121
+
122
+
Node-RED defines a set of environment variables for exposing information about the nodes, flows and groups.
123
+
124
+
This information helps "locate" the node in your [workspace](/docs/user-guide/editor/workspace/index.md). Nodes in your workspace exist as part of a [flow](/docs/user-guide/editor/workspace/flows.md). Likewise, a node may (or may not) be part of a [group](/docs/user-guide/editor/workspace/groups.md). Nodes, flows and groups are each given unique IDs that are generated by Node-RED.
125
+
126
+
Nodes, flows and groups all support the `name` property, which you can change when [editing properties](/docs/user-guide/editor/workspace/nodes.md#editing-node-properties).
127
+
128
+
The following environment variables can be used to access this information for a given node:
129
+
130
+
-`NR_NODE_ID` - the ID of the node
131
+
-`NR_NODE_NAME` - the Name of the node
132
+
-`NR_NODE_NAME` - 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.
133
+
-`NR_GROUP_ID` - the ID of the containing group
134
+
-`NR_GROUP_NAME` - the Name of the containing group
135
+
-`NR_FLOW_ID` - the ID of the flow the node is on
136
+
-`NR_FLOW_NAME` - the Name of the flow the node is on
97
137
138
+
Note that while the IDs generated by Node-RED are guaranteed to be unique, the names are not. If a node, flow or group does not have a given name, the corresponding environment variable will be an empty string. If a node is not part of a group, its group id environment variable will also return an empty string.
0 commit comments