Providing private nodes – use package.json

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). 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.

Shouldn't a "private" node be considered as node development and installed as such ?

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.

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:

   "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.

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...

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.

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.

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.

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.

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.

1 Like

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.

I think the most generic way would be to enable the settings.js "nodesDir" entry to also 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)