# Change Serial COM Port from webpage

**URL:** <https://discourse.nodered.org/t/change-serial-com-port-from-webpage/74461>\
**Category:** General\
**Tags:** uibuilder\
**Created:** [31 January 2023 04:44 UTC](https://discourse.nodered.org/t/change-serial-com-port-from-webpage/74461 "2023-01-31T04:44:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johrdan](https://avatars.discourse-cdn.com/v4/letter/j/f07891/32.png) [@Johrdan](https://discourse.nodered.org/u/Johrdan)\
**Post date:** [31 January 2023 04:44 UTC](https://discourse.nodered.org/t/change-serial-com-port-from-webpage/74461/1 "2023-01-31T04:44:59Z")

</div>

Hi, I am using Node-RED to connect my laptop to a device that has serial communication and is connected to COM5. I am receiving the data in Node-RED through a serial in node and showing the data in a webpage by using uibuilder nodes.  
I am looking for a way to change the serial COM port (for example, change "COM5" to "COM6") from the webpage, so that the user does not have to go to the node-red flow to change it. For this, I assume I need to have access to a variable that is associated with the COM port name of the "serial in" node. Do you know how to access this variable or if there is a way to achieve this? Thanks in advance.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/e/fe507d33f27d1e7d050b21895029c777c5b7d0a5.png)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [31 January 2023 05:41 UTC](https://discourse.nodered.org/t/change-serial-com-port-from-webpage/74461/2 "2023-01-31T05:41:36Z")

</div>

I don't think this is possible.

Serial port is connected to hardware, it requires proper closing/opening of the port, which is done upon deploy I believe.

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [31 January 2023 08:29 UTC](https://discourse.nodered.org/t/change-serial-com-port-from-webpage/74461/3 "2023-01-31T08:29:13Z")

</div>

Don't think that is is possible with the NR serial port.  
Maybe you can do something with **Web Serial** , it's the possiblity to communicate from you browser (Chrome) with a serial port.

> **[serialport-binding-webserialapi](https://www.npmjs.com/package/serialport-binding-webserialapi)**
>
> Web Serial API binding for Node Serialport. Latest version: 1.0.3, last published: 2 years ago. Start using serialport-binding-webserialapi in your project by running \`npm i serialport-binding-webserialapi\`. There is 1 other project in the npm...

Never used it myself in this way.

---

<div class="post-metadata">

**Author:** ![magicfire](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/magicfire/32/93420_2.png) [@magicfire](https://discourse.nodered.org/u/magicfire)\
**Post date:** [31 January 2023 08:36 UTC](https://discourse.nodered.org/t/change-serial-com-port-from-webpage/74461/4 "2023-01-31T08:36:45Z")

</div>

Hi, why not change a way to consider the whole thing.  
How about change the lap-top to a device which has a fixed com port?  
**For commercial purpose** , I introduce this netGate for you.  
[PN6400](https://item.taobao.com/item.htm?spm=a21dvs.23580594.0.0.3c3a645ewGVSYZ&ft=t&id=698582740166)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [31 January 2023 08:39 UTC](https://discourse.nodered.org/t/change-serial-com-port-from-webpage/74461/5 "2023-01-31T08:39:29Z")

</div>

> [@Johrdan](#):
>
> looking for a way to change the serial COM port (for example, change "COM5" to "COM6") from the webpage, so that the user does not have to go to the node-red flow to change it

One possibility is to use environment variables. You could have the user enter a comport number In dashboard, then in your flows, you could write this to a file and reboot node red. In your settings.js file you could read this value in and store it in the in process.env.COMPORT. lastly set the comport to `${COMPORT}`

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [31 January 2023 20:36 UTC](https://discourse.nodered.org/t/change-serial-com-port-from-webpage/74461/6 "2023-01-31T20:36:37Z")

</div>

And that's the issue isn't it. To change node-red's com ports, you do have to restart node-red.

Certainly uibuilder can be your front end as long as you can work out the back-end method.

Unfortunately, I'm not aware of a way to "fix" the com port on windows like you can on Linux. But as you say Steve, you could have a function in your settings.js or some other node-red startup script that detects the correct port and sets the environment variable suitably. Not totally dynamic but it would remove the need from the users altogether.

---

<div class="post-metadata">

**Author:** ![Johrdan](https://avatars.discourse-cdn.com/v4/letter/j/f07891/32.png) [@Johrdan](https://discourse.nodered.org/u/Johrdan)\
**Post date:** [4 February 2023 20:12 UTC](https://discourse.nodered.org/t/change-serial-com-port-from-webpage/74461/7 "2023-02-04T20:12:26Z")

</div>

Hi, Steve. I created a .env file that is in the .node-red folder. In the webpage, the user can select a COM port. For example, if the user selects COM5, the plotlatlon node writes "COMPORT=COM5" to the .env file. In settings.js, I wrote require('dotenv').config() to include the environment variable from this file. However, when I restart node-red, ${COMPORT} does not update. But when I force it and write process.env.COMPORT = 'COM5', the serial in node starts working. Am I missing something?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/9/49028b19bb87dd23b3820c029f8846b356ba16ac.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f63a7e0eda9ae97c7cea84405b0e7877cad723c0.png)

---

<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:** [5 April 2023 20:13 UTC](https://discourse.nodered.org/t/change-serial-com-port-from-webpage/74461/8 "2023-04-05T20:13:07Z")

</div>

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