如何在节点红色中设置环境变量?

时间:2018-09-24 18:01:04

标签: javascript environment-variables node-red

我是使用Node-Red进行开发的新手,正在寻找一种将值集作为环境变量导入到我的流程中的方法。

非常感谢您对此提供的任何帮助。

3 个答案:

答案 0 :(得分:1)

由于node-RED版本为0.19,因此更容易将环境变量导入流中。

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

示例:使用更改节点读取环境变量COMPUTERNAME:

[{"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

答案 1 :(得分:0)

您可以使用process.env对象设置环境变量。即:

process.env.SOME_VAR = "VALUE";

并获取值:

var someData = process.env.SOME_VAR || "default value";

答案 2 :(得分:0)

除了AIOT MAKER建议的方法外,还可以使用$env()函数在表达式中访问环境变量。