简体   繁体   中英

MQTT node password via env var

Trying to populate the MQTT node (native with node red) with variables from environment variables. I have used the ${} and $() notations in the flows.json and also tried process.env.VAR in settings.js. the username and hostnames work (I assume as they are text fields) but the password does not render, instead, it saves the env variable name rather than its contents. ie: $(MQTT_PASSWORD) rather than "password" .

Has anyone solved this issue? or have information on it?

The reason to use env-vars in a node's property is to allow it to be set dynamically whenever Node-RED starts.

If it substituted the env-var with its value at the point you saved the flow configuration, then it would hardcoded to that value and you wouldn't be able to change the env-var in the future. This is why the saved configuration still has $(MQTT_PASSWORD) .

The runtime takes care of substituting the current value of the env-var when it creates the instance of the node in question on startup.

Here is my flows.cred file. The referenced node is an MQTT Configuration node. It seems to be working:

{
    "edf18224.a363e": {
        "user": "${MQTT_USER}",
        "password": "${MQTT_PASSWORD}"
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM