# Report import of EnvironmentFile in Node-red console / log

**URL:** https://discourse.nodered.org/t/report-import-of-environmentfile-in-node-red-console-log/89673
**Category:** Feature Requests
**Tags:** linux
**Created:** [22 July 2024 15:05 UTC](https://discourse.nodered.org/t/report-import-of-environmentfile-in-node-red-console-log/89673 "2024-07-22T15:05:58Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [22 July 2024 15:05 UTC](https://discourse.nodered.org/t/report-import-of-environmentfile-in-node-red-console-log/89673/1 "2024-07-22T15:05:58Z")

</div>

## Background
On Linux Node-red can be executed in various ways:
1. `sudo systemctl enable nodered` & reboot
2. `sudo systemctl [re]start nodered`
3. `node-red-start`
4. `node-red-pi`
5. `node-red`

Edit - corrected (swapped 3 & 4), added 5.  
1, 2 and 3 will (always - assuming the OS supports systemd?) start Node-red as a systemd service using the script at `/lib/systemd/system/nodered.service`  
In this case, any environment variables specified in a file `~/.node-red/EnvironmentFile` will be inherited by Node-red `*`

4 and 5 start Node-red directly, not using the systemd script, so the file is not imported.  
~~Note that node-red-start is very widely recommended as the start-up command of choice despite it bypassing this and other advantages of the systemd script file.~~

`*` Or it may be `~/.node-red/environment`, depending on the installer script version _first used_ on that machine.

## Problem
The confusingly varied startup behaviour makes it hard to tell if required environment variables have actually been imported.
## Proposal
\*\*1\*\* Add `dd mmm HH:MM:SS - [info] Environment file : /home/pi/.node-red/EnvironmentFile` to the current information in the Node-red log:

```auto
22 Jul 15:34:20 - [info] Node-RED version: v4.0.0-beta.4
22 Jul 15:34:20 - [info] Node.js version: v20.15.1
22 Jul 15:34:20 - [info] Linux 6.6.31+rpt-rpi-v8 arm64 LE
22 Jul 15:34:20 - [info] Loading palette nodes
22 Jul 15:34:22 - [info] Dashboard version 3.6.5 started at /ui
22 Jul 15:34:23 - [info] Settings file : /home/pi/.node-red/settings.js
22 Jul 15:34:23 - [info] Context store : 'memoryOnly' [module=memory]
22 Jul 15:34:23 - [info] Context store : 'file' [module=localfilesystem]
22 Jul 15:34:23 - [info] User directory : /home/pi/.node-red
**************** This line
22 Jul 15:34:23 - [info] Environment file : /home/pi/.node-red/EnvironmentFile   
****************
22 Jul 15:34:23 - [warn] Projects disabled : editorTheme.projects.enabled=false
22 Jul 15:34:23 - [info] Flows file : /home/pi/.node-red/flows.json
22 Jul 15:34:23 - [info] Server now running at http://127.0.0.1:1880/

```

**2** Bring the script node-red-start into line with the systemd script.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [22 July 2024 15:46 UTC](https://discourse.nodered.org/t/report-import-of-environmentfile-in-node-red-console-log/89673/2 "2024-07-22T15:46:13Z")

</div>

> [@jbudd](#):
>
> 3 `node-red-pi`  
> 4 `node-red-start`
> 
> 1, 2 and 3 will (always?) start Node-red as a systemd service

It is 1, 2 and 4 that start it as a service.  
3 (node-red-pi) and 5 (node-red) start it in the current window.

Edit: I don't know what the difference between node-red and node-red-pi is. Calling either with `--help` yields the same output.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [22 July 2024 16:18 UTC](https://discourse.nodered.org/t/report-import-of-environmentfile-in-node-red-console-log/89673/3 "2024-07-22T16:18:50Z")

</div>

> [@Colin](#):
>
> It is 1, 2 and 4 that start it as a service.  
> 3 (node-red-pi) and 5 (node-red) start it in the current window.

Hmm is that right? I could have sworn I'd checked and shuffled them around to get like methods together.

Just underlines how confusing these different options are.

And I'd forgotten just plain `node-red`even though I use that after every reinstallation

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [22 July 2024 16:41 UTC](https://discourse.nodered.org/t/report-import-of-environmentfile-in-node-red-console-log/89673/4 "2024-07-22T16:41:27Z")

</div>

> [@jbudd](#):
>
> Hmm is that right?

Run node-red-start and it tells you it starting as a service.

```auto
node-red-start

Start Node-RED
 
Once Node-RED has started, point a browser at http://192.168.49.92:1880
On Pi Node-RED works better with the Firefox or Chrome browser
 
Use node-red-stop to stop Node-RED
Use node-red-start to start Node-RED again
Use node-red-log to view the recent log output
Use sudo systemctl enable nodered.service to autostart Node-RED at every boot
Use sudo systemctl disable nodered.service to disable autostart on boot
 
To find more nodes and example flows - go to http://flows.nodered.org
 
Starting as a systemd service.

```

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [22 July 2024 16:43 UTC](https://discourse.nodered.org/t/report-import-of-environmentfile-in-node-red-console-log/89673/5 "2024-07-22T16:43:54Z")

</div>

Yes I just got to my PC and tried it, hopefully corrected the original post.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [22 July 2024 21:17 UTC](https://discourse.nodered.org/t/report-import-of-environmentfile-in-node-red-console-log/89673/6 "2024-07-22T21:17:43Z")

</div>

Are you sure the environment file is not read when it is run not as a service?

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [22 July 2024 22:32 UTC](https://discourse.nodered.org/t/report-import-of-environmentfile-in-node-red-console-log/89673/7 "2024-07-22T22:32:03Z")

</div>

Well I'm sure the environment variables are not set, and since it's the systemd script which references the file ...

```auto
EnvironmentFile=-/home/pi/.node-red/EnvironmentFile

```

Here is an example:  
EnvironmentFile contains

```auto
pi@AlsoPi:~/.node-red $ cat EnvironmentFile
MQTT_BROKER='broker.hivemq.com'
MQTT_TOPIC='topic/from/EnvironmentFile'

```

This is the flow. Note two different ways to refer to environment variables in the inject node.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/4/14fdf89836a15a173a3e3066187805fe13dcfa98.png)

```auto
[{"id":"c0c11435666359ac","type":"inject","z":"654f55124d2a7bb4","name":"Inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"${MQTT_TOPIC}","payload":"MQTT_BROKER","payloadType":"env","x":130,"y":840,"wires":[["b15b20cf035d36f3"]]},{"id":"b15b20cf035d36f3","type":"debug","z":"654f55124d2a7bb4","name":"From Environment","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":310,"y":840,"wires":[]}]

```

After `sudo systemctl restart node-red` the debug output shows the file is imported.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/a/5af14aae046860755b4830ae57c0d71d9aaf42f6.png)

After `sudo systemctl stop node-red` and `node-red` it shows that the environment variables are not set.  
msg.topic gets the variable name as a string literal because this field is injected as a string.  
msg.payload is blank because it's injected as type Environment variable.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/d/5d8facc2cc31dd47e8f717e011ba2e113ec160d4.png)

And note that this example is Node-red 4 but the filename in systemd is `EnvironmentFile` because [an earlier version of] Node-red was previously installed.  
If I were to reflash the SD card and install again, I believe the filename would be `environment`

---

<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: [20 September 2024 22:32 UTC](https://discourse.nodered.org/t/report-import-of-environmentfile-in-node-red-console-log/89673/8 "2024-09-20T22:32:16Z")

</div>

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