Question about name space for name scoped nodes

Hi I am working on my first custom node and have some very basic questions

  1. Is there a particular preferred namespace for the scoped names used for new nodes?
    i.e. in @myScope/node-red-contrib-my-node,
    is myScope a) my username in the node red forum
    b) my npm username used to publish the package
    c) my github username used to host the repo
    d) or some random string that I generate.

Thanks

Would be worth reading this blog post: Introducing the Node Scorecard : Node-RED

And the packaging section in the docs: Creating Nodes : Node-RED

Thanks for the quick reply

I realised after rereading the packaging section that there is a hyperlink on that page to the following

That page contains the following
...
Each npm user/organization has their own scope, and only you can add packages in your scope. This means you don't have to worry about someone taking your package name ahead of you. Thus it is also a good way to signal official packages for organizations.
...

That would seem to imply that the user scope would be defined by my npm userid

Yes, it is your npm userid.

Previously, we asked that if a module’s name started with node-red- , that it use node-red-contrib- to distinguish it from modules maintained by the core project.

With the scoped prefix, it is no longer suggested to have the "contrib" part in your node name based on that linked post.

The small issue you could have is that if you are publishing @tonymacdonald/node-red-my-node and somebody else has already published node-red-contrib-my-node, then maybe you might both name your node my-node which could cause a conflict. Unless there has been some change, I do not think the @scoped-name will help in this situation.

A good reason to also scope the registration...

RED.nodes.registerType("@me/my-node",MyNode)
3 Likes

That's a good idea. Seems so obvious now that you have pointed it out. Was that documented anywhere?

It would be useful I think if there were a specific section on Scoping of packages and node types in the Creating Nodes docs. I have not created any nodes since scoping was introduced so don't feel qualified to do this myself.

I did use the scoped registration for a new node I'm developing for a project at work.

One problem I stumbled upon was with the nodes section in the package.json.

  "node-red": {
    "version": ">=1.0.0",
    "nodes": {
      "@me/my-node": "nodes/my-node.js"
    }
  },

Using a slash / as scope delimiter will crash the runtime as soon as someone accesses the editor in a browser.
with a

TypeError: Cannot read properties of undefined (reading 'user')

in the following line: (Node-Red v3.0.2)

As a workaround, I used @me-my-node instead of @me/my-node, which is working as expected.

Are these property names from package.json of any relevance or can these just be arbitrary? After all, the names that actually get used are ones from the RED.nodes.registerType('@me/my-node') call.

And another thing I just found... :see_no_evil:

Using the slash also seems to break credentials when the editor tries to load them via

http://localhost:1880/credentials/@me/my-node/eaecb0950c9394f5

The slash adds another path element the the URL, which results - of course - in a 404 error. This one might be trickier to fix in the backend.

So my conclusion for now:

  • scoped node registrations: good idea
  • but: using a - instead of / as delimiter to avoid those edge cases
2 Likes

And, of course, do a sanity check on node names before starting work. Both avoiding "obvious", generic words (e.g. "chart" would obviously be a very bad choice, "ui-chartjs" would be a fairly bad choice unless you intend to provide wide-ranging support for that library for all use-cases in Dashboard) and searching the flows site for the name you are thinking of.

Thanks for all the great discussion on this topic

I understand that the new model requires custom node packages to be published with scoped names and from the responses here and the documentation I can see how to do that.

However, it was not clear to me that the names of the nodes within that package also have to be scoped.
If there is no need to scope the names of the nodes within the package, then the "@me/" wouldn't be required in the nodes: entry below

  "node-red": {
    "version": ">=1.0.0",
    "nodes": {
      "@me/my-node": "nodes/my-node.js"
    }
  },

Is it really necessary to scope the names of the nodes within the package?

The names do not need to be scoped. However, there is always the danger of a name clash so choosing node names wisely is a necessity.

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