Just created node (not saved) and RED.nodes.getNode

Hi!

  1. own created node.
  2. drop my node to flow
  3. set configuration in the field
    image
  4. trying lookup some information based on configuration field
    server: { value: "", type: "hc2-server-config", required: true },
    (ip/login/pwd) via Fibaro Home Center
  5. code
    var node = RED.nodes.getNode(req.params.id);
    if (node !== null && typeof node !== "undefined") {

so, if flow with this node is NOT saves - node is NULL
otherwise OK.

my question is, why I can't start design node at runtime when a node is not saved yet.

thank you!

Sorry, I don't fully follow your question.

Can you provide some more details?

Where are you trying to lookup the information? How are you doing that?

Where is that code?

module.exports = function (RED) {
RED.nodes.registerType("hc2-device", Node);

function Node(n) {
    RED.nodes.createNode(this, n);
    var node = this;
 }

    RED.httpAdmin.get("/fibaroSearch/:id/*", function (req, res) {

        RED.log.debug("GET /fibaroSearch");
        var node = RED.nodes.getNode(req.params.id);
        if (node !== null && typeof node !== "undefined") {

        } else {
                 // if node not saved I'm here.
        }

module.exports = function (RED) {
    "use strict";
    function HelloWorldNode(config) {

        RED.nodes.createNode(this, config);
        var node = this;
        this.on('input', function (msg) {
            msg.payload = "Hello";
            node.send(msg);
        });

       	RED.httpAdmin.get("/test/:id/*", function (req, res) {
            var node = RED.nodes.getNode(req.params.id);
            if (node !== null && typeof node !== "undefined") {
		RED.log.warn("OK");
		var lookup = [];
                lookup.push({"label": "One", "value": 1});
		lookup.push({"label": "Two", "value": 2});
		lookup.push({"label": "Three", "value": 3});
                res.json(lookup || []);
            } else {
                RED.log.warn("Oops!");
		res.json([]);
            }
        });

    }
    RED.nodes.registerType("hello", HelloWorldNode);
};

<script type="text/javascript">
    RED.nodes.registerType('hello',{
        category: 'function',
        color: '#e2d96e',
        defaults: {
            name: {value:"", required: true}
        },
        inputs:1,
        outputs:1,
        icon: "white-globe.png",
        label: function() {
            return this.name||"hello";
        },
        oneditprepare: function () {
            var node = this;

            try {
                $("#node-input-name").autocomplete("destroy");
            } catch (err) { }

            $("#node-lookup-name").click(function () {
                $("#node-lookup-name-icon").removeClass('fa-search');
                $("#node-lookup-name-icon").addClass('spinner');
                $("#node-lookup-name").addClass('disabled');
                $.getJSON('test/' + node.id + "/", { search: $("#node-input-name").val() }, function (data) {
                    //$.getJSON('fibaroSearch/' + node.id + "/" + $("#node-input-name").val(), function (data) {
                    $("#node-lookup-name-icon").addClass('fa-search');
                    $("#node-lookup-name-icon").removeClass('spinner');
                    $("#node-lookup-name").removeClass('disabled');
                    var search = [];
                    $.each(data, function (i, item) {
                        search.push(item);
                    });
                    $("#node-input-name").autocomplete({
                        source: search,
                        minLength: 0,
                        select: function (event, ui) {
                            $(this).val(ui.item.label);
                            $("#node-input-deviceID").val(ui.item.value);
                            return false;
                        },
                        change: function (event, ui) {
                            //console.log("change");
                        },
                        close: function (event, ui) {
                            $("#node-input-name").autocomplete("destroy");
                        }
                    }).autocomplete("search", $("#node-input-name").val());

                });
            });
        },

    });
</script>

<script type="text/x-red" data-template-name="hello">
    <div class="form-row">
        <label for="node-input-name"><i class="icon-bookmark"></i> Name</label>
        <input type="text" id="node-input-name" style="width:60%;" placeholder="garage light sensor"/>
        <a id="node-lookup-name" class="btn"><i id="node-lookup-name-icon" class="fa fa-search"></i></a>
    </div>

</script>

<script type="text/x-red" data-help-name="hello">
    <p>A simple node that changes the message payloads to Hello</p>
</script>

sample project

Hi - I was asking for more explanation, not more code. So I've now had to study you code to figure out what you are asking.

A node does not exist in the runtime until it has been deployed.

If you need the runtime to do something for a node you are still configuring and have not deployed, you'll need to pass all the required information as a part of the HTTP request you make to the runtime.

Oops!
but thank you so much for reply!