# Using environment variables in kafka consumer topic

**URL:** https://discourse.nodered.org/t/using-environment-variables-in-kafka-consumer-topic/99321
**Category:** General
**Tags:** kafka
**Created:** [8 October 2025 19:54 UTC](https://discourse.nodered.org/t/using-environment-variables-in-kafka-consumer-topic/99321 "2025-10-08T19:54:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![JeroenVH](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jeroenvh/32/53766_2.png) [@JeroenVH](https://discourse.nodered.org/u/JeroenVH)
#### Post date: [8 October 2025 19:54 UTC](https://discourse.nodered.org/t/using-environment-variables-in-kafka-consumer-topic/99321/1 "2025-10-08T19:54:19Z")

</div>

The project that I am working on uses the `hylink/node-red-kafka-client` nodes.

I have different flows with identical nodes and configured an environment variable at the flow level to make things inside the flow unique.

I am now looking for a way to configure the kafka consumer node to use a topic that is parameterized with the environment variable. The topic is a UNS-like string and I need to get the unit name from the environment variable.

Is this possible? Or do I have to use another kafka library?

Also, is it possible to leave the topic blank (or default) with the produce node use the topic provided by the message?

---

<div class="post-metadata">

### Author: ![JeroenVH](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jeroenvh/32/53766_2.png) [@JeroenVH](https://discourse.nodered.org/u/JeroenVH)
#### Post date: [13 October 2025 13:40 UTC](https://discourse.nodered.org/t/using-environment-variables-in-kafka-consumer-topic/99321/2 "2025-10-13T13:40:57Z")

</div>

To answer my own question, it is possible to use an environment variable as the topic in the kafka node. You can [not substitute](https://nodered.org/docs/user-guide/environment-variables#:~:text=This%20only%20works%20if%20it%20replaces%20the%20entire%20property%20-%20it%20cannot%20be%20used%20to%20substitute%20just%20part%20of%20the%20value.%20For%20example%252C%20it%20is%20not%20possible%20to%20use%20CLIENT-%2524%7BHOST%7D) part of the topic, you need to have the complete topic as an environment variable.

The environment variable on the other hand can be composed with a JSONata expression.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [27 October 2025 13:41 UTC](https://discourse.nodered.org/t/using-environment-variables-in-kafka-consumer-topic/99321/3 "2025-10-27T13:41:51Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
