# Sharing config nodes between separate packages

**URL:** <https://discourse.nodered.org/t/sharing-config-nodes-between-separate-packages/47547>\
**Category:** Developing Nodes\
**Created:** [23 June 2021 19:11 UTC](https://discourse.nodered.org/t/sharing-config-nodes-between-separate-packages/47547 "2021-06-23T19:11:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdkrieg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mdkrieg/32/39091_2.png) [@mdkrieg](https://discourse.nodered.org/u/mdkrieg)\
**Post date:** [23 June 2021 19:11 UTC](https://discourse.nodered.org/t/sharing-config-nodes-between-separate-packages/47547/1 "2021-06-23T19:11:18Z")

</div>

Hello,

I recently decided to separate one of my node-red-contrib packages into two packages. I did this because some of the nodes were becoming redundant but offered a simpler method of usage.

My problem is that they both use the same config node to store an external API key and I would like for it to remain generic & common.

#### First attempt - wishful thinking

I tried adding the following checks before registering the node in both the .js and .html files but I was still getting warnings about an already registered node

```
if(!RED.nodes.registry.getNodeType("alpaca-config")){
    RED.nodes.registerType('alpaca-config',{
//-----------------------node definition here
    });
}
if(!RED.nodes.getType("alpaca-config")){
    RED.nodes.registerType('alpaca-config',{
//-----------------------node definition here
    });
}

```

I think it was the fact that "alpaca-config" was still defined in my package.json so I gave up on this approach.

#### Current solution - copy the dashboard nodes...

I realized this is a similar situation to the dashboard nodes, how there are separate packages that share the same group and tab nodes. Looking in there it seems that the "ui\_group" is specified in node-red-dashboard and that all the peripheral packages call up ui\_group from this package.

This is the approach I have taken and it works, but I would really like for a user to be able to pick one or the other package instead of requiring the primary package to be installed.

#### Possible solution - will this work?

I got to thinking, that maybe this problem can be solved with NPM. What if I separate out this configuration node into yet a third package and make it a dependency of both of my user-level packages, this should be a viable solution right? I guess my only question is will I need to register this config-level node with [nodered.org](http://nodered.org) or just publish it to npmjs? I see that nodered no longer automatically registers packages with the node-red tag so perhaps this is a use-case for that middle ground?

I know I could just try it out and see but I wanted to get some thoughts as I'm really out on a limb at this point.

Thanks for your time,  
-Matt

---

<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:** [23 June 2021 19:45 UTC](https://discourse.nodered.org/t/sharing-config-nodes-between-separate-packages/47547/2 "2021-06-23T19:45:13Z")

</div>

> [@mdkrieg](#):
>
> What if I separate out this configuration node into yet a third package and make it a dependency of both of my user-level packages, this should be a viable solution right? I guess my only question is will I need to register this config-level node with [nodered.org](http://nodered.org) or just publish it to npmjs?

Hi Matthew,  
We had a discussion last week (see [here](https://discourse.nodered.org/t/inheritance-of-custom-nodes/47282/6)) which might give you some ideas, because it was also about code sharing.

> [@mdkrieg](#):
>
> I tried adding the following checks before registering the node in both the .js and .html files but I was still getting warnings about an already registered node

It is not clear to me why that code snippet doesn't work. At first sight it seems a reasonable good idea to me. Would be nice if somebody could enlighten the both of us...

Bart

---

<div class="post-metadata">

**Author:** ![mdkrieg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mdkrieg/32/39091_2.png) [@mdkrieg](https://discourse.nodered.org/u/mdkrieg)\
**Post date:** [23 June 2021 21:11 UTC](https://discourse.nodered.org/t/sharing-config-nodes-between-separate-packages/47547/3 "2021-06-23T21:11:22Z")

</div>

> [@BartButenaers](#):
>
> It is not clear to me why that code snippet doesn't work. At first sight it seems a reasonable good idea to me. Would be nice if somebody could enlighten the both of us...

I took a second look at my first approach just to make sure I wasn't dizzy and missed something. Same result, only way to get no conflict warnings is to remove the config.js from package.json.

Even more confusing is I put an else{ console.log("-----skipping config node"); } on the end of my check (plus one at the beginning of the .js) and I get no message in the node console or in my browser console. I'm definitely missing something. (edit: I even tried changing the index name of the .js in my package.json to "something-else":"config.js" and it still clashes)

Looks like you folks in the linked thread are discussing a use-case far more complicated than what I'm trying to do which has inspired me to go for it. I'm going to separate my config node into a dependency and I'll report back how it goes 🙂

---

<div class="post-metadata">

**Author:** ![mdkrieg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mdkrieg/32/39091_2.png) [@mdkrieg](https://discourse.nodered.org/u/mdkrieg)\
**Post date:** [23 June 2021 22:51 UTC](https://discourse.nodered.org/t/sharing-config-nodes-between-separate-packages/47547/4 "2021-06-23T22:51:35Z")

</div>

Well, there were some growing pains, but the separate package option works!

One growing pain I experienced was I originally thought to rename the node to something else when separating it out but this caused all my flows to break!

My thought was that if someone had "mismatched" versions of the sibling projects they would get the same clash I was trying to avoid but I don't think that is the worse issue.

Thanks for the input!  
-Matt

---

<div class="post-metadata">

**Author:** ![mdkrieg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mdkrieg/32/39091_2.png) [@mdkrieg](https://discourse.nodered.org/u/mdkrieg)\
**Post date:** [23 June 2021 23:03 UTC](https://discourse.nodered.org/t/sharing-config-nodes-between-separate-packages/47547/5 "2021-06-23T23:03:32Z")

</div>

For posterity, one other thing I noticed is that apparently npm install doesn't install dependencies if using a local file location (ie. "npm install ~/environment/node-red-contrib-..." . I had to upload everything to github first and then it worked as expected.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 July 2021 23:03 UTC](https://discourse.nodered.org/t/sharing-config-nodes-between-separate-packages/47547/6 "2021-07-07T23:03:58Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
