Search code examples
javascriptenvironment-variablesnode-red

How to set environment variables in node red?


I am new to development using Node-Red and was looking for a way to import a value set as an Environment Variable into one of my flows.

Would highly appreciate any help regarding this.


Solution

  • Since node-RED version 0.19 it is easier to import environment variables into flows.

    Source: https://nodered.org/blog/2018/08/14/version-0-19-released

    Example: read environment variable COMPUTERNAME, using a change node:

    [{"id":"d17299e5.9ff148","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"d66f687a.d01248","type":"change","z":"d17299e5.9ff148","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"COMPUTERNAME","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":140,"wires":[["67cb1bc6.0b3724"]]},{"id":"578fe08e.8f056","type":"inject","z":"d17299e5.9ff148","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":140,"wires":[["d66f687a.d01248"]]},{"id":"67cb1bc6.0b3724","type":"debug","z":"d17299e5.9ff148","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":580,"y":140,"wires":[]}]
    

    enter image description here