I like to use a os variable in my flow, the hostname.
So i added a line in (top) of settings.js
(Nodered is installed as a docker container on a rpi 4b, with the latest image/container of NR)
process.env.hostname = require('os').hostname();
in my flow i use
var theHost = global.get('env').hostname();
msg.payload = theHost;
and get: TypeError: Cannot read property 'hostname' of undefined
I also tried
var theHost = global.get('env');
msg.payload = theHost.hostname;
Tried this (no os var but a self decalred var
//added to top settings.js --> process.env.MY_ENV_VAR = "Hello World";
var theHost = env.get("MY_ENV_VAR")
but no hello world, but strange content
Added this in settings.js
process.env.MY_ENV_VAR = "Hello World";
and in the flow inject node i did:
msg.payload = global.env.MY_ENV_VAR
That should work -
env.get(...) eventually does look up from
Did you remember to restart Node-RED after editing your settings file?
yes i did, stopped and restarted the docker...
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.