# Node-red running port to variable

**URL:** <https://discourse.nodered.org/t/node-red-running-port-to-variable/42495>\
**Category:** General\
**Created:** [11 March 2021 16:49 UTC](https://discourse.nodered.org/t/node-red-running-port-to-variable/42495 "2021-03-11T16:49:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![narc0z](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/narc0z/32/38669_2.png) [@narc0z](https://discourse.nodered.org/u/narc0z)\
**Post date:** [11 March 2021 16:49 UTC](https://discourse.nodered.org/t/node-red-running-port-to-variable/42495/1 "2021-03-11T16:49:21Z")

</div>

Hello! How can I retrieve the port that node-red is running on (ex. 1880) and use it as any form of variable inside the editor? I am eventually looking to have several instances running with same settings and userDir (node-red -p 1881 and so on..), I have a python script that is called within node-red that returns data back to node-red via the HTTP (post) node, I need to feed this python script the correct port so it knows which instance to report back to. Thanks!

---

<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:** [11 March 2021 17:22 UTC](https://discourse.nodered.org/t/node-red-running-port-to-variable/42495/2 "2021-03-11T17:22:58Z")

</div>

If you set an env var and use that in the node-red start up, it will be accessible in a function as `env.get('xxx')` or an inject using the environment variable selection and in JSONata as `$env('xxx')`

NOTE: I am faily certain if you set PORT=1889 in the env starting node-red (without the -p param) node-red will use PORT and you can access `env.get('PORT')` in a function (or as described above)

---

<div class="post-metadata">

**Author:** ![narc0z](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/narc0z/32/38669_2.png) [@narc0z](https://discourse.nodered.org/u/narc0z)\
**Post date:** [11 March 2021 18:46 UTC](https://discourse.nodered.org/t/node-red-running-port-to-variable/42495/3 "2021-03-11T18:46:30Z")

</div>

Your solution in your NOTE section works perfectly, and I am able to retrieve the port with env var inside the editor, I am running node-red under windows currently:

```auto
set PORT=1881
node-red
11 Mar 13:42:03 - [info] Server now running at http://127.0.0.1:1881

```

Thank you Steve-Mcl.

---

<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:** [25 March 2021 18:47 UTC](https://discourse.nodered.org/t/node-red-running-port-to-variable/42495/4 "2021-03-25T18:47:22Z")

</div>

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