# Providing private nodes – use package.json

**URL:** <https://discourse.nodered.org/t/providing-private-nodes-use-package-json/12686>\
**Category:** Feature Requests\
**Created:** [28 June 2019 12:19 UTC](https://discourse.nodered.org/t/providing-private-nodes-use-package-json/12686 "2019-06-28T12:19:44Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![pelis](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pelis/32/5055_2.png) [@pelis](https://discourse.nodered.org/u/pelis)\
**Post date:** [28 June 2019 12:19 UTC](https://discourse.nodered.org/t/providing-private-nodes-use-package-json/12686/1 "2019-06-28T12:19:45Z")

</div>

In the newer releases of node-red you seem to have changed the file structure regarding nodes.  
You have introduced @node-red and below that you are now storing your core nodes.

It seems you are no longer looking into …/node-red\_install\_dir/node\_modules/ to find additional nodes. I had installed private nodes in that place (due to npm issues: [https://github.com/npm/npm/issues/17379](https://github.com/npm/npm/issues/17379)). Everything worked find in previous releases of node-red, now private nodes are no longer found in that location.

I have moved my private nodes into a new place:  
…/node-red\_user\_dir/nodes/myPrivateNodes/

All nodes are found and loaded. However, the mechanism to load such private nodes from this location seems not to use package.json where you find the list of nodes and the order of such nodes accordingly in the section "node-red": {"nodes": {…}}.  
If you put such private nodes into …/node-red\_user\_dir/, the loading behaviour does take package.json into account, which is the preferred loading behaviour – at least to me. This is my change request.

So there are different loading behaviours, depending on where you locate private nodes.  
I would appreciate if you could make that consistent - and use package.json as you do when loading from the .node-red user dir.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [28 June 2019 12:23 UTC](https://discourse.nodered.org/t/providing-private-nodes-use-package-json/12686/2 "2019-06-28T12:23:36Z")

</div>

Shouldn't a "private" node be considered [as node development and installed as such](https://nodered.org/docs/creating-nodes/first-node#testing-your-node-in-node-red) ?

---

<div class="post-metadata">

**Author:** ![pelis](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pelis/32/5055_2.png) [@pelis](https://discourse.nodered.org/u/pelis)\
**Post date:** [28 June 2019 12:30 UTC](https://discourse.nodered.org/t/providing-private-nodes-use-package-json/12686/3 "2019-06-28T12:30:49Z")

</div>

In my case, I have a bundle of multiple nodes.  
Such nodes sit in the same location and share code together.  
I want the nodes to be displayed in the palette in a specific order. That order is defined in the package.json file which defines the setup for the entire bundle.  
As mentioned in my post, everything works as expected when I put my private nodes "bundle" in the .node-red user directory.  
It just behaves differently when I chosse a different location to store the nodes.

---

<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:** [28 June 2019 12:47 UTC](https://discourse.nodered.org/t/providing-private-nodes-use-package-json/12686/4 "2019-06-28T12:47:25Z")

</div>

Hi @Pelis,

The npm issue you linked to highlights the fact that npm will remove modules that are not listed in package.json.

The answer here is to install your custom module in `~/.node-red` in such a way to get a proper entry in the `package.json` file.

Lets assume your custom module is in the directory `~/code/my-node`.

You can then run `npm install ../code/my-node` from the `~/.node-red` directory. This will install your module and add an entry to package.json similar to:

```auto
   "my-node": "file:../code/my-node"

```

That _should_ keep everything happy.

The `nodes` directory is more for local development before you have a fully packaged node. It's a bit of a legacy feature to be honest - it does have real-world uses but they are somewhat edge cases. There hasn't been a compelling need to change the logic here given you can put proper modules in the usual place.

---

<div class="post-metadata">

**Author:** ![pelis](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pelis/32/5055_2.png) [@pelis](https://discourse.nodered.org/u/pelis)\
**Post date:** [28 June 2019 15:09 UTC](https://discourse.nodered.org/t/providing-private-nodes-use-package-json/12686/5 "2019-06-28T15:09:01Z")

</div>

Thanks Nick,

it works the way you describe it. npm will create an npm link which is not really nice...  
Just for my better understanding:  
You are saying that the '~.node-red/nodes' is not really the place for custom nodes.  
Is that also true for the optional 'nodesDir:' entry in settings.js?

Is there a reason why you are no longer looking into '~node-red/node\_modules' as you did in earlier releases ?

thanks again...

---

<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:** [28 June 2019 15:17 UTC](https://discourse.nodered.org/t/providing-private-nodes-use-package-json/12686/6 "2019-06-28T15:17:27Z")

</div>

> [@pelis](#):
>
> it works the way you describe it. npm will create an npm link which is not really nice...

To help me understand your concerns, what do you think is not nice about this? It is the way `npm` supports having unpublished modules in your node\_modules directory.

> [@pelis](#):
>
> You are saying that the '~.node-red/nodes' is not really the place for custom nodes.

It is not the place for custom node _modules_. This is how it is today - that doesn't mean we can't review it. However I'm not yet convinced of a need to have two places right next to each other (`~/.node-red/node_modules` and `~/.node-red/nodes`) for providing modules.

There probably _is_ value in allowing the `nodesDir` setting to point to a location that may contain modules as well as 'local' nodes.

> [@pelis](#):
>
> Is there a reason why you are no longer looking into '~node-red/node\_modules' as you did in earlier releases ?

I'm not sure which dir you are referring to there. If you mean `~/.node-red/node_modules` then that is absolutely where we look for modules.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [28 June 2019 15:33 UTC](https://discourse.nodered.org/t/providing-private-nodes-use-package-json/12686/7 "2019-06-28T15:33:12Z")

</div>

> [@knolleary](#):
>
> This is how it is today - that doesn't mean we can't review it. However I'm not yet convinced of a need to have two places right next to each other ( `~/.node-red/node_modules` and `~/.node-red/nodes` ) for providing modules.

Hi Nick,  
I hope when you say "However I'm not yet convinced of a need to have two places right next to each other" that you are dont plan on removing the `nodes` folder functionality?

Personally, I copy private nodes into `nodes` folder(without the chew on of npm etc) and it just works - beautifully.

Regards.

---

<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:** [28 June 2019 15:35 UTC](https://discourse.nodered.org/t/providing-private-nodes-use-package-json/12686/8 "2019-06-28T15:35:12Z")

</div>

> [@Steve-Mcl](#):
>
> dont plan on removing the `nodes` folder functionality?

No. The question is whether we _add_ support for loading node modules from the `nodes` directory. My point was not being convinced we need two locations right next to each other for loading _modules_ from.

---

<div class="post-metadata">

**Author:** ![pelis](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pelis/32/5055_2.png) [@pelis](https://discourse.nodered.org/u/pelis)\
**Post date:** [28 June 2019 15:40 UTC](https://discourse.nodered.org/t/providing-private-nodes-use-package-json/12686/9 "2019-06-28T15:40:53Z")

</div>

With '~node-red/node\_modules' I mean the node-red install directory (where you start red.js). When that directory had a node\_modules directory which contained custom nodes such nodes had been loaded.

npm link: OK, I agree. In Windows environments I experienced that the npm link gets lost unexpectedly. But that has been quiet a while ago...

'~.node-red/nodes': You are right, that does not really make sense. I am just looking for a way how I can easily deploy local nodes that will not get deleted when a public node gets installed via npm.

---

<div class="post-metadata">

**Author:** ![pelis](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pelis/32/5055_2.png) [@pelis](https://discourse.nodered.org/u/pelis)\
**Post date:** [29 June 2019 08:29 UTC](https://discourse.nodered.org/t/providing-private-nodes-use-package-json/12686/10 "2019-06-29T08:29:17Z")

</div>

I think the most generic way would be to enable the settings.js "nodesDir" entry to also look for modules

---

<div class="post-metadata">

**Author:** ![pelis](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pelis/32/5055_2.png) [@pelis](https://discourse.nodered.org/u/pelis)\
**Post date:** [2 July 2019 08:44 UTC](https://discourse.nodered.org/t/providing-private-nodes-use-package-json/12686/11 "2019-07-02T08:44:13Z")

</div>

> [@knolleary](#):
>
> I'm not sure which dir you are referring to there. If you mean `~/.node-red/node_modules` then that is absolutely where we look for modules.

Could you confirm that the latest releases of node-red no longer search for modules in e.g. '/user/home/node\_modules/node-red/node\_modules'.  
As this seems to be the case I would highly appreciate if you would also look for modules in nodesDir (settings.js)
