Search code examples
portnode-red

Node Red get instance port


i have a server that starts 10 instance of node-red on different port . with a php page i redirect my users on their port. I need that every node- red instance can get its port but there isn't a node that get localhost:1889 for example (i need 1889). i'm searching on google from 2 days but nothing


Solution

  • One approach is to set the port on each instance using an environment variable and attaching that to the Node-RED instance using the global variables section of settings.js.

    That makes the port available to logic within your flows.

    functionGlobalContext: {
        instancePort: process.env.PORT
    },
    

    In Node-RED you can then access that variable via a change node or in a function node.