Search code examples
node-red

Set host from environment variable in HTTP request node


I have a node-red HTTP Request node. I want to use as url, something like this:

http://SERVER_HOST:SERVER_PORT/

How can I substitute server_host and server_port with their equivalent value from the environment?

I don't want to add another node just to set this url, if possible

I've tried:

${SERVER_HOST}
$(SERVER_HOST)
$env(SERVER_HOST)

${'SERVER_HOST'}
$('SERVER_HOST')
$env('SERVER_HOST')

Solution

  • You can only set the whole value from a single environment variable directly in nodes configuration.

    So you have 2 options:

    1. Set the whole URL as environment variable e.g. $(SERVER_URL)
    2. Use a function node before hand to assemble the parts and set it as msg.url and then pass that into the HTTP-request node.