Node-red running port to variable

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!

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)


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:

set PORT=1881
11 Mar 13:42:03 - [info] Server now running at

Thank you Steve-Mcl.


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