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
Copy file name to clipboardExpand all lines: docs/user-guide/environment-variables.md
+52-29Lines changed: 52 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,24 +60,14 @@ function:
60
60
let foo =env.get("FOO");
61
61
```
62
62
63
-
### Built-In Environment Variables
64
-
65
-
*Since Node-RED 2.2*
63
+
### Template node
66
64
67
-
Node-RED maintains its own set of environment variables for exposing information about the node itself. 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.
68
-
69
-
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).
The following environment variables can be used to access this contextual information for the node.
72
-
73
-
- `NR_NODE_ID`
74
-
- `NR_NODE_NAME`
75
-
- `NR_GROUP_ID`
76
-
- `NR_GROUP_NAME`
77
-
- `NR_FLOW_ID`
78
-
- `NR_FLOW_NAME`
79
-
80
-
Note that while the IDs generated by Node-RED are guaranteed to be unique, the names are not. If a node, flow or group is not given a name, then the corresponding environment variable will return an empty string. If a node is not part of a group, its group id environment variable will also return an empty string.
67
+
The `template` node can access environment variables using the syntax:
68
+
```
69
+
My favourite colour is {{env.COLOUR}}
70
+
```
81
71
82
72
### Subflow Instance properties
83
73
@@ -90,28 +80,61 @@ a subflow could be created to access the API and handle the response, using an
90
80
environment variable to identify which type of record should be accessed. Individual
91
81
instances of the Subflow can then be customised for those particular types.
92
82
93
-
### Flow/Group level environment variable
94
83
95
-
Since 2.21, environment variables can be set for Flow or Group on their settings panel.
96
84
97
-
### Predefined environment variable
85
+
### Flow/Group level environment variables
98
86
99
-
Since 2.22, following predefined environment variables has been added that provides access to information about the node, group and flow.
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.
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
+
102
+
### Running as a service
103
+
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:
105
+
106
+
```
107
+
process.env.FOO='World';
108
+
```
109
+
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
+
112
+
```
113
+
ENV_VAR='foobar'
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:
100
129
101
130
-`NR_NODE_ID` - the ID of the node
102
131
-`NR_NODE_NAME` - the Name of the node
103
-
-`NR_NODE_NAME` - the Path of the node
104
-
105
-
The node's path represents a node's hierarchy in a flow. It is `/`
106
-
delimited IDs of the flow, enclosing subflows, and 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.
107
133
-`NR_GROUP_ID` - the ID of the containing group
108
134
-`NR_GROUP_NAME` - the Name of the containing group
109
135
-`NR_FLOW_ID` - the ID of the flow the node is on
110
136
-`NR_FLOW_NAME` - the Name of the flow the node is on
111
137
112
-
### Accessing nested environment variable
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.
139
+
113
140
114
-
Environment variable definition is searched from the bottom to the top
115
-
of the node's definition hierarchy. `$ parent.` prefix can be added to
116
-
environment variable name (e.g. `$parent.NR_GROUP_NAME`) to move the
117
-
start position of this search up one level in the hierarchy.
0 commit comments