Is there a way to read current node config data in RED.httpAdmin.get function?


#1

Hi all,

I'm trying to expose a REST endpoint inside a node.
I would like to use a node config property inside of it (I don't want to fire the flow).

This is the code:

function MyNode(config) {
    RED.nodes.createNode(this, config);
    this.myproperty = config.myproperty;
    node.on('input', function (msg) {
    // ...
        node.send(msg);
    });
}

RED.nodes.registerType("myNode", MyNode);


RED.httpAdmin.get("/myendpoint", function (req, res) {
    // how to read node.myproperty?
});

#2

To get a config property from settings.js, use RED.settings.<varname>.

You can't directly access a node instance property since your API is set up outside the registration function - as it should be. If you need a node instance property, add it as a request parameter to the API call. Just don't forget to sanitise any API parameters to prevent security issues.