# Improve TCP nodes (IP and Port programmatically)

**URL:** https://discourse.nodered.org/t/improve-tcp-nodes-ip-and-port-programmatically/66780
**Category:** Feature Requests
**Created:** [22 August 2022 21:29 UTC](https://discourse.nodered.org/t/improve-tcp-nodes-ip-and-port-programmatically/66780 "2022-08-22T21:29:01Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![maximus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maximus/32/66678_2.png) [@maximus](https://discourse.nodered.org/u/maximus)
#### Post date: [22 August 2022 21:29 UTC](https://discourse.nodered.org/t/improve-tcp-nodes-ip-and-port-programmatically/66780/1 "2022-08-22T21:29:01Z")

</div>

Hi,  
It would be nice if the IP and Port on the TCP nodes could be inserted with variables or through messages.

Thanks!

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [22 August 2022 22:06 UTC](https://discourse.nodered.org/t/improve-tcp-nodes-ip-and-port-programmatically/66780/2 "2022-08-22T22:06:19Z")

</div>

The tcp-request node supports this as it is intended for short lived connections. The in and out nodes are more intended for long lasting connections either as a server or client, so are not expected to change hosts and ports, though they can be set as environment variables.

---

<div class="post-metadata">

### Author: ![maximus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maximus/32/66678_2.png) [@maximus](https://discourse.nodered.org/u/maximus)
#### Post date: [22 August 2022 22:55 UTC](https://discourse.nodered.org/t/improve-tcp-nodes-ip-and-port-programmatically/66780/3 "2022-08-22T22:55:18Z")

</div>

Thanks for the reply.

I didn't know the field could take environment variables.

My goal is to load the IP and port from a configuration file.  
Would you know if I can put these into a specific file instead of using settings.js (as explained in the Node-Red documentation)?

Thank you.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [22 August 2022 23:11 UTC](https://discourse.nodered.org/t/improve-tcp-nodes-ip-and-port-programmatically/66780/4 "2022-08-22T23:11:50Z")

</div>

Well settings.js is an executable file so it can be edited to add code to read in from another file if you wish. Or you can set env variables outside of node-red before starting it.

---

<div class="post-metadata">

### Author: ![dptek](https://avatars.discourse-cdn.com/v4/letter/d/f1d935/32.png) [@dptek](https://discourse.nodered.org/u/dptek)
#### Post date: [8 September 2022 11:52 UTC](https://discourse.nodered.org/t/improve-tcp-nodes-ip-and-port-programmatically/66780/5 "2022-09-08T11:52:51Z")

</div>

How can set the tcp-in node to listen a port that is set on an environment variable?  
Edit: I mean the tcp-in node working as a server.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [8 September 2022 12:35 UTC](https://discourse.nodered.org/t/improve-tcp-nodes-ip-and-port-programmatically/66780/6 "2022-09-08T12:35:12Z")

</div>

> [@dptek](#):
>
> How can set the tcp-in node to listen a port that is set on an environment variable

You can use an environment variable in any field in any node using `${ENV_VAR}` in the node configuration. See [Using environment variables : Node-RED](https://nodered.org/docs/user-guide/environment-variables)

---

<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: [7 November 2022 12:35 UTC](https://discourse.nodered.org/t/improve-tcp-nodes-ip-and-port-programmatically/66780/7 "2022-11-07T12:35:25Z")

</div>

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