# Does a sidebar node has a server side instance?

**URL:** <https://discourse.nodered.org/t/does-a-sidebar-node-has-a-server-side-instance/18392>\
**Category:** Developing Nodes\
**Created:** [25 November 2019 12:17 UTC](https://discourse.nodered.org/t/does-a-sidebar-node-has-a-server-side-instance/18392 "2019-11-25T12:17:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [25 November 2019 12:17 UTC](https://discourse.nodered.org/t/does-a-sidebar-node-has-a-server-side-instance/18392/1 "2019-11-25T12:17:46Z")

</div>

Hi folks,

It seems like I am somehow misinterpreting how sidebar nodes work 😩  
My server side part is never called:

```auto
function XtermSidebarNode(config) {
   RED.nodes.createNode(this, config);
   console.log("THIS TEXT NEVER APPEARS IN THE LOG ;-( ")
}
RED.nodes.registerType("xterm_sidebar", XtermSidebarNode);

```

I 'suppose' that is not normal (??), because when I look at the [node-red-contrib-contextbrowser](https://github.com/sbarwe/node-red-contrib-contextbrowser/blob/master/contextbrowser.js#L23) node, the guy has added some functionality on server-side ...

But then I don't understand where the sidebar node 'should' be created. Because a user never explicit adds such a node to it's flow (like you do with non-sidebar nodes). Instead the sidebar tabsheet is added dynamically as soon as the node is added to the pallette in the flow editor:

```auto
<script type="text/javascript">  
(function() {
    RED.nodes.registerType('xterm_sidebar',{
        category: 'config',
        exclusive: true,,
        defaults: {
            ...
        },
        onpaletteadd: function () {
            RED.sidebar.addTab({
                id: "sidebar-xterm",
                label: "terminal_xterm",
                name: "Terminal",
                content: content,
                closeable: true,
                disableOnEdit: true,
                iconClass: "fa fa-terminal",
            });
        },
        onpaletteadd: function () {
             // HERE I ALSO NEVER ARRIVE ...
        }
    });
})();
</script>

```

Should I create the instance by myself somehow? Or is there perhaps never an instance?  
Would be nice if anybody could explain me a bit in detail how this mechanism works.

Thanks !!  
Bart

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [25 November 2019 12:47 UTC](https://discourse.nodered.org/t/does-a-sidebar-node-has-a-server-side-instance/18392/2 "2019-11-25T12:47:13Z")

</div>

> [@BartButenaers](#):
>
> Would be nice if anybody could explain me a bit in detail how this mechanism works.

As I've said, there is no established pattern for this and it is a whole area that hasn't been documented.

There is no such thing as a "sidebar node". There are flow nodes and config nodes. The `contextbrowser` module registers a config node to the palette because that is the only way to get anything loaded by the runtime and into the editor. It's a hack that is required because we don't provide any alternative. And in the contextbrowser case, the config node it registers exists _only_ as a means to deliver code to the editor. The config node is never added to a flow, nor does it do anything in the runtime.

Your case is different. You want to use the config node in order to store settings in the flow related to your sidebar. As I mentioned, the only example I know for that is Node-RED Dashboard and its `ui_base` node.

That node has a function called [`ensureDashboardNode`](https://github.com/node-red/node-red-dashboard/blob/master/nodes/ui_base.html#L1108) that does the work to add a new `ui_base` node if its needed. That function is then called at various points when the user interacts with the dashboard sidebar. As I mentioned before, it has to deal with various edge cases, such as the user importing a second ui\_base node, or explicitly deleting it from the Config node sidebar.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [25 November 2019 13:11 UTC](https://discourse.nodered.org/t/does-a-sidebar-node-has-a-server-side-instance/18392/3 "2019-11-25T13:11:22Z")

</div>

> [@knolleary](#):
>
> That node has a function called [`ensureDashboardNode`](https://github.com/node-red/node-red-dashboard/blob/master/nodes/ui_base.html#L1108)

Yes that was indeed a good pointer in our last conversation!  
I have meanwhile added a similar function to my node, to register a config node & set the workspace as dirty & check every time that nobody has deleted the config node behind my back. That all works nice, although I am still _'very'_ aware of the fact that this is not documented and not a public API...

> [@knolleary](#):
>
> There is no such thing as a "sidebar node".

Ah that was my mistake. I had created both a sidebar-node (html & js file) **AND** a config-node (html & js file). But now I understand it works like this:

1. I only need to register a config node
2. As soon as the config node is added to the palette, it will add a tabsheet to the sidebar.
3. Inside the sidebar code I create an instance of that config node (like I already do).

That would simplify things ...
