# Write node source code?

**URL:** https://discourse.nodered.org/t/write-node-source-code/30516
**Category:** Developing Nodes
**Created:** [21 July 2020 23:26 UTC](https://discourse.nodered.org/t/write-node-source-code/30516 "2020-07-21T23:26:21Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)
#### Post date: [21 July 2020 23:26 UTC](https://discourse.nodered.org/t/write-node-source-code/30516/1 "2020-07-21T23:26:21Z")

</div>

While learning how to write node code, I came across an error, that I did not understand. The error message in the log referenced that I had a type that was already registered?

For example the following generates the error... Node function name was 'si'...

```auto
RED.nodes.registerType("si",si);

```

But the following does not... Node function name was siNode of course...

```auto
RED.nodes.registerType("si",siNode);

```

Not understanding how a function name would conflict with a registered type? I take it this is something with the native to NR design or even node js? I found the documentation reference to how HTML and JS files link via the register type definition, but not how the function name in the js file would conflict with same.

---

<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: [22 July 2020 08:48 UTC](https://discourse.nodered.org/t/write-node-source-code/30516/2 "2020-07-22T08:48:53Z")

</div>

I can't see how the function name has any bearing at all. The only thing that will cause the issue you describe is if `RED.nodes.registerType` is called more than once with `"si"` as its first argument.

---

<div class="post-metadata">

### Author: ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)
#### Post date: [22 July 2020 12:57 UTC](https://discourse.nodered.org/t/write-node-source-code/30516/3 "2020-07-22T12:57:54Z")

</div>

So the error message maybe a bit misleading? But the fix, really was making sure the node function name was not the same as the registered type label/name. I see the same thing in many examples of node red modules, the registered type name is 'X' and the actual function name is 'XNode' for example. Even the official documented example uses 'lower-case' as the registered type, and the actual function name is 'LowerCaseNode'. They are never the same it appears.

---

<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: [22 July 2020 13:25 UTC](https://discourse.nodered.org/t/write-node-source-code/30516/4 "2020-07-22T13:25:43Z")

</div>

> [@Nodi.Rubrum](#):
>
> So the error message maybe a bit misleading? But the fix, really was making sure the node function name was not the same as the registered type label/name.

Not necessarily.

I just did a quick test registering a node whose type matched the name of its function - and it worked fine.

At this point, I think you accidentally ended up with two separate calls to `RED.nodes.registerType` happening for the same `"si"` type.

---

<div class="post-metadata">

### Author: ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)
#### Post date: [22 July 2020 13:36 UTC](https://discourse.nodered.org/t/write-node-source-code/30516/5 "2020-07-22T13:36:15Z")

</div>

Ah, ok... either way it was a rookie mistake, what I did. I went back and make sure my naming of types and functions as correct, and the issue resolved. Just seemed odd to me, but I am new to custom node development, so still tripping over stuff, as I learn.

---

<div class="post-metadata">

### Author: ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)
#### Post date: [22 July 2020 17:17 UTC](https://discourse.nodered.org/t/write-node-source-code/30516/6 "2020-07-22T17:17:38Z")

</div>

Yeah, but to fix it... all I did was a 'Node' to the function name. But either way, discussed and done. I should have named the function better anyway, to match what is the common practice type of thing.

---

<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: [20 September 2020 17:17 UTC](https://discourse.nodered.org/t/write-node-source-code/30516/7 "2020-09-20T17:17:51Z")

</div>

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