Custom node without input

Hello,

I've been experimenting with custom nodes and I try to create a node that will output once two messages and that has no input. In the html file I've already specified that I have no input and two outputs. My problem is in the .js file. In all of the examples that I've seen the .js file is written like this:

module.exports = function(RED) {
    function MyFunction(config) {
        RED.nodes.createNode(this,config);
        // some stuff to deal with the defaults of the html file
        var node = this;
        node.on('input', function(msg)) {
            // my function
            node.send(msg);
        }
    }
    RED.nodes.registerType("my-function",MyFunction);
}

The problem is that I do not have an input to trigger node.on, so how do I do this part?

The sourcecode for all the Input nodes is available on the github site.

1 Like
module.exports = function(RED) {
    function MyFunction(config) {
        RED.nodes.createNode(this,config);

           msg = {"payload":"bla"}
           node.send(msg);
           node.send(msg);
    }
    RED.nodes.registerType("my-function",MyFunction);
}
1 Like

If you have no input, what are you going to trigger it with.? Whatever it is - whenever you receive that - is when you then call node.send.

1 Like

It should trigger itself after deploy (maybe with a short delay).

Thank you! I'll try that.