# Accessing environment details from a Node-red flow

**URL:** <https://discourse.nodered.org/t/accessing-environment-details-from-a-node-red-flow/95807>\
**Category:** General\
**Created:** [5 March 2025 13:59 UTC](https://discourse.nodered.org/t/accessing-environment-details-from-a-node-red-flow/95807 "2025-03-05T13:59:20Z")\
**Posts on this page:** 10\
**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:** [5 March 2025 13:59 UTC](https://discourse.nodered.org/t/accessing-environment-details-from-a-node-red-flow/95807/1 "2025-03-05T13:59:21Z")

</div>

The node-red usage message (on Linux) shows that you can specify various runtime settings (irrelevant options removed from example):

```auto
node-red --help
Node-RED v4.0.9
Usage: node-red [--settings settings.js] [--userDir DIR]
                [--port PORT] [flows.json]

```

- How can a flow discover the current pathnames of the directory, settings & flows files and port?

I suspect this requires use of the admin API?

I have asked an AI to write me a function to do this but it's answers, of course, are [expletive deleted].

I'm interested particularly on NR running on Linux, but a cross-platform solution would be a bonus.

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [5 March 2025 16:56 UTC](https://discourse.nodered.org/t/accessing-environment-details-from-a-node-red-flow/95807/2 "2025-03-05T16:56:08Z")

</div>

With the `diagnostics` endpoint. You can try with the `Show System Info` action.

---

<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:** [5 March 2025 16:57 UTC](https://discourse.nodered.org/t/accessing-environment-details-from-a-node-red-flow/95807/3 "2025-03-05T16:57:51Z")

</div>

Is there an example flow somewhere that shows how to do that?

I see this page [https://nodered.org/docs/api/admin/methods/get/diagnostics/](https://nodered.org/docs/api/admin/methods/get/diagnostics/) which documents the response object but not how to get there.

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [5 March 2025 17:14 UTC](https://discourse.nodered.org/t/accessing-environment-details-from-a-node-red-flow/95807/4 "2025-03-05T17:14:31Z")

</div>

Complete the `Authorization` then it should work

```json
[{"id":"7aab978c3ba7bde7","type":"inject","z":"15cdbf1d258ebb57","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":340,"wires":[["31434da3af04fa94"]]},{"id":"22b3a08164c63aba","type":"debug","z":"15cdbf1d258ebb57","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":480,"y":340,"wires":[]},{"id":"31434da3af04fa94","type":"http request","z":"15cdbf1d258ebb57","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://localhost:1880/diagnostics","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"other","keyValue":"Accept","valueType":"other","valueValue":"application/json"},{"keyType":"other","keyValue":"Authorization","valueType":"other","valueValue":"Bearer [token]"}],"x":310,"y":340,"wires":[["22b3a08164c63aba"]]}]

```

Full version:

```json
[{"id":"7aab978c3ba7bde7","type":"inject","z":"15cdbf1d258ebb57","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"client_id\":\"node-red-admin\",\"grant_type\":\"password\",\"scope\":\"*\",\"username\":\"admin\",\"password\":\"password\"}","payloadType":"json","x":130,"y":420,"wires":[["23ad1faed6ab4680"]]},{"id":"22b3a08164c63aba","type":"debug","z":"15cdbf1d258ebb57","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":420,"wires":[]},{"id":"31434da3af04fa94","type":"http request","z":"15cdbf1d258ebb57","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://localhost:1880/diagnostics","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"other","keyValue":"Accept","valueType":"other","valueValue":"application/json"},{"keyType":"other","keyValue":"Authorization","valueType":"msg","valueValue":"payload"}],"x":630,"y":420,"wires":[["22b3a08164c63aba"]]},{"id":"23ad1faed6ab4680","type":"http request","z":"15cdbf1d258ebb57","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://localhost:1880/auth/token","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":290,"y":420,"wires":[["ff30f98494e9198a"]]},{"id":"ff30f98494e9198a","type":"function","z":"15cdbf1d258ebb57","name":"function 1","func":"msg.payload = \"Bearer \" + JSON.parse(msg.payload)[\"access_token\"];\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":420,"wires":[["31434da3af04fa94"]]}]

```

---

<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:** [5 March 2025 18:54 UTC](https://discourse.nodered.org/t/accessing-environment-details-from-a-node-red-flow/95807/5 "2025-03-05T18:54:17Z")

</div>

OK thanks.  
Now I can get the name (not the full pathname) of the flows file from /diagnostics

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/6/168c5ad646dcb3ecb234ad62ca7b0bdea37bb471.png)  
But I can't find the settings file in any of the API methods?

To be clear, these are the values I'm trying to obtain:

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

---

<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:** [6 March 2025 23:01 UTC](https://discourse.nodered.org/t/accessing-environment-details-from-a-node-red-flow/95807/6 "2025-03-06T23:01:41Z")

</div>

I conclude that it's not possible via the admin API so the fallback seems to be the exec node

```auto
journalctl --boot=0 --grep="Settings file" --lines=1 --output=cat | awk '{print $NF}'
and 
journalctl --boot=0 --grep="Flows file" --lines=1 --output=cat | awk '{print $NF}'

```

which gives `/home/pi/.node-red/settings.js` and `/home/pi/.node-red/flows.json`

Unfortunately while the above works if you start Node-red with node-red-start or the systemd script, it seems that the output from `node-red --settings nonStandardSettings.js nonStandardFlows.json` is not logged. Rather strange.

---

<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:** [7 March 2025 09:02 UTC](https://discourse.nodered.org/t/accessing-environment-details-from-a-node-red-flow/95807/7 "2025-03-07T09:02:52Z")

</div>

> [@jbudd](#):
>
> if you start Node-red with node-red-start or the systemd script, it seems that the output from `node-red --settings nonStandardSettings.js nonStandardFlows.json` is not logged.

When you run `node-red --settings ...` that runs node-red in the command window. When you run it via the systemd script it uses the command line parameters specified in the script. The command  
`systemctl cat nodered`  
will show you the script. In particular, if you uncomment the line  
`#Environment="NODE_RED_OPTIONS=-v"`  
you can put the settings file option in there  
`Environment="NODE\_RED\_OPTIONS='--settings /path/to/nonStandardSettings.js'"  
then I think that will do it. I have not tested it however, so the syntax may not be completely correct.

If you are running it as a service then you can reduce the amount of output from journalctl by adding `-u nodered` so it only shows output from the nodered 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:** [7 March 2025 09:59 UTC](https://discourse.nodered.org/t/accessing-environment-details-from-a-node-red-flow/95807/8 "2025-03-07T09:59:09Z")

</div>

Thanks Colin.

I did not know about `systemctl cat nodered`, did know about (but omitted) -u nodered

I was interested to discover within a flow what settings and flows file it is using, regardless of how it was started up.

Actually the journalctl approach even if it worked would probably fall down on a device with two Node-red instances running.

---

<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:** [7 March 2025 10:25 UTC](https://discourse.nodered.org/t/accessing-environment-details-from-a-node-red-flow/95807/9 "2025-03-07T10:25:37Z")

</div>

Also, on a pi, I think the journal is not file based so if node red has been running for a month then it will be long gone.

You could set something in your settings file that identifies which file it is, which you can interrogate at run time.

---

<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:** [5 June 2025 10:26 UTC](https://discourse.nodered.org/t/accessing-environment-details-from-a-node-red-flow/95807/10 "2025-06-05T10:26:33Z")

</div>

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