# Opening node-red

**URL:** <https://discourse.nodered.org/t/opening-node-red/39665>\
**Category:** General\
**Created:** [24 January 2021 18:17 UTC](https://discourse.nodered.org/t/opening-node-red/39665 "2021-01-24T18:17:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mas](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Mas](https://discourse.nodered.org/u/Mas)\
**Post date:** [24 January 2021 18:17 UTC](https://discourse.nodered.org/t/opening-node-red/39665/1 "2021-01-24T18:17:03Z")

</div>

Hi, when I want to open node-red, I faced an error. Can you help me to resolve it??

TypeError: Cannot read property 'forEach' of undefined  
at Object.addModule (C:\Users\Admin\AppData\Roaming\npm\node\_modules\node-red\node\_modules@node-red\registry\lib\registry.js:186:27)  
at C:\Users\Admin\AppData\Roaming\npm\node\_modules\node-red\node\_modules@node-red\registry\lib\loader.js:108:30  
at tryCatchReject (C:\Users\Admin\AppData\Roaming\npm\node\_modules\node-red\node\_modules\when\lib\makePromise.js:845:30)  
at runContinuation1 (C:\Users\Admin\AppData\Roaming\npm\node\_modules\node-red\node\_modules\when\lib\makePromise.js:804:4)  
at Fulfilled.when (C:\Users\Admin\AppData\Roaming\npm\node\_modules\node-red\node\_modules\when\lib\makePromise.js:592:4)  
at Pending.run (C:\Users\Admin\AppData\Roaming\npm\node\_modules\node-red\node\_modules\when\lib\makePromise.js:483:13)  
at Scheduler.\_drain (C:\Users\Admin\AppData\Roaming\npm\node\_modules\node-red\node\_modules\when\lib\Scheduler.js:62:19)  
at Scheduler.drain (C:\Users\Admin\AppData\Roaming\npm\node\_modules\node-red\node\_modules\when\lib\Scheduler.js:27:9)  
at processTicksAndRejections (internal/process/task\_queues.js:75:11)

---

<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:** [24 January 2021 19:49 UTC](https://discourse.nodered.org/t/opening-node-red/39665/2 "2021-01-24T19:49:28Z")

</div>

How/where are you running Node-RED?

---

<div class="post-metadata">

**Author:** ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)\
**Post date:** [24 January 2021 20:40 UTC](https://discourse.nodered.org/t/opening-node-red/39665/3 "2021-01-24T20:40:05Z")

</div>

And have you installed any 3rd party (self developed) nodes before it failed?

---

<div class="post-metadata">

**Author:** ![Mas](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Mas](https://discourse.nodered.org/u/Mas)\
**Post date:** [25 January 2021 09:12 UTC](https://discourse.nodered.org/t/opening-node-red/39665/4 "2021-01-25T09:12:07Z")

</div>

> [@hardillb](#):
>
> 3rd party (self developed) nodes

when I type node-red in Node.js command prompt.

I receive this:

# Welcome to Node-RED

25 Jan 10:10:58 - [info] Node-RED version: v1.2.7  
25 Jan 10:10:58 - [info] Node.js version: v14.15.4  
25 Jan 10:10:58 - [info] Windows\_NT 10.0.19041 x64 LE  
25 Jan 10:10:58 - [info] Loading palette nodes  
25 Jan 10:11:01 - [error] Failed to start server:  
25 Jan 10:11:01 - [error] TypeError: Cannot read property 'forEach' of undefined  
at Object.addModule (C:\Users\Admin\AppData\Roaming\npm\node\_modules\node-red\node\_modules@node-red\registry\lib\registry.js:186:27)  
at C:\Users\Admin\AppData\Roaming\npm\node\_modules\node-red\node\_modules@node-red\registry\lib\loader.js:108:30  
at tryCatchReject (C:\Users\Admin\AppData\Roaming\npm\node\_modules\node-red\node\_modules\when\lib\makePromise.js:845:30)  
at runContinuation1 (C:\Users\Admin\AppData\Roaming\npm\node\_modules\node-red\node\_modules\when\lib\makePromise.js:804:4)  
at Fulfilled.when (C:\Users\Admin\AppData\Roaming\npm\node\_modules\node-red\node\_modules\when\lib\makePromise.js:592:4)  
at Pending.run (C:\Users\Admin\AppData\Roaming\npm\node\_modules\node-red\node\_modules\when\lib\makePromise.js:483:13)  
at Scheduler.\_drain (C:\Users\Admin\AppData\Roaming\npm\node\_modules\node-red\node\_modules\when\lib\Scheduler.js:62:19)  
at Scheduler.drain (C:\Users\Admin\AppData\Roaming\npm\node\_modules\node-red\node\_modules\when\lib\Scheduler.js:27:9)  
at processTicksAndRejections (internal/process/task\_queues.js:75:11)

---

<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:** [25 January 2021 09:13 UTC](https://discourse.nodered.org/t/opening-node-red/39665/5 "2021-01-25T09:13:12Z")

</div>

Hi @Mas

how did you install Node-RED?

We have seen this error before on Windows, but I cannot immediately remember what caused it, other than it was an 'unusual' install.

---

<div class="post-metadata">

**Author:** ![Mas](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Mas](https://discourse.nodered.org/u/Mas)\
**Post date:** [25 January 2021 09:15 UTC](https://discourse.nodered.org/t/opening-node-red/39665/6 "2021-01-25T09:15:04Z")

</div>

Yes, I installed some, but know I do not remember which one was the last self developed node.

---

<div class="post-metadata">

**Author:** ![Mas](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Mas](https://discourse.nodered.org/u/Mas)\
**Post date:** [25 January 2021 09:16 UTC](https://discourse.nodered.org/t/opening-node-red/39665/7 "2021-01-25T09:16:39Z")

</div>

I install node-red on Windows. I was working well, and suddenly I faced this error!

---

<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:** [25 January 2021 09:36 UTC](https://discourse.nodered.org/t/opening-node-red/39665/8 "2021-01-25T09:36:34Z")

</div>

That does suggest it will be related to one of the extra nodes you have installed.

Can you work backwards and uninstall each module in turn to see which broke things?

---

<div class="post-metadata">

**Author:** ![Mas](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Mas](https://discourse.nodered.org/u/Mas)\
**Post date:** [25 January 2021 13:11 UTC](https://discourse.nodered.org/t/opening-node-red/39665/9 "2021-01-25T13:11:56Z")

</div>

I have removed nodes which are called node-red-contrib-...  
by entering npm remove node-red-contrib-...  
But still, it does not work!

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [25 January 2021 17:59 UTC](https://discourse.nodered.org/t/opening-node-red/39665/10 "2021-01-25T17:59:40Z")

</div>

You have a couple of options at this point.

Possibly the easiest is to take a copy of your flows and credentials json files and put them somewhere safe. Then delete them from your userDir and restart Node-RED so that they are recreated from scratch.

Then you can import your saved flow but when you do so, delete as much as possible before you commit it. Then restart Node-RED again so that you know whether you have hit the issue. Of course, you will need to install nodes along the way. Just take it slow and steady so that you find where the issue lies.

I recently had a similar issue and it drove me mad because I thought it was being caused by a dependent module that I'd loaded. In fact, it was simply a missing global variable that had been deleted. What confused me was that the module I'd installed (not a node) was making extensive use of promises and it caused the error message stack to look rather odd.

* * *

The other thing you could do if you know how to do node.js debugging would be to temporarily put a breakpoint on the line of code in Node-RED that is reporting the error then you could step through things and find out which node is being loaded when the error occurs.

@knolleary should there be a test before that line of code to catch that error?

> <https://github.com/node-red/node-red/blob/master/packages/node_modules/@node-red/registry/lib/registry.js#L185-L187>

Looks like there should be something to test whether `set.types` exists or perhaps rather whether it is an array before trying to apply `.forEach`?

---

<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:** [25 January 2021 18:06 UTC](https://discourse.nodered.org/t/opening-node-red/39665/11 "2021-01-25T18:06:55Z")

</div>

> [@TotallyInformation](#):
>
> You have a couple of options at this point.

Another option, that is slightly less drastic, is to look in the file `~/.node-red/.config.nodes.json` - this will give you a list of the extra nodes the runtime is still trying to load. Check through those to see if any of them are causing the issue.

> [@TotallyInformation](#):
>
> should there be a test before that line of code to catch that error?

Yes, but that would just mask the error. I can't remember what root cause we discovered for this last time - but it was sufficiently of a nature that I didn't rush to add error handling for it. It could have been a badly implemented custom node someone was working on locally. If I can track it down, I'll see where we got to on it.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [25 January 2021 20:37 UTC](https://discourse.nodered.org/t/opening-node-red/39665/12 "2021-01-25T20:37:16Z")

</div>

> [@knolleary](#):
>
> that would just mask the error

I was thinking that the test would create `set.err` which other errors in the same area create so that something useful could be reported back.

It looks as though there is a node that hasn't defined any `types`. Presumably `setName` is the name of the thing being loaded and so could be reported back.

Small change to the addModule function would do the job. I've tested this and it works as expected (this from v1.2.7 code, I note that the dev branch is marginally different).

```auto
function addModule(module) {
    moduleNodes[module.name] = [];
    moduleConfigs[module.name] = module;
    for (var setName in module.nodes) {
        if (module.nodes.hasOwnProperty(setName)) {
            var set = module.nodes[setName];
            moduleNodes[module.name].push(set.name);
            nodeList.push(set.id);
            if (!set.err) {
                if ( ! Array.isArray(set.types) ) {
                    set.err = "Type not defined - check node definition";
                    set.err.code = "type_not_defined";
                    set.err.details = {
                        moduleB: set.module
                    }
                } else {
                    set.types.forEach(function(t) {
                        if (nodeTypeToId.hasOwnProperty(t)) {
                            set.err = "Type already registered";
                            set.err.code = "type_already_registered";
                            set.err.details = {
                                type: t,
                                moduleA: getNodeInfo(t).module,
                                moduleB: set.module
                            }

                        }
                    });
                }
                if (!set.err) {
                    set.types.forEach(function(t) {
                        nodeTypeToId[t] = set.id;
                    });
                }
            }
        }
    }
    if (module.icons) {
        icon_paths[module.name] = icon_paths[module.name] || [];
        module.icons.forEach(icon=>icon_paths[module.name].push(path.resolve(icon.path)) )
    }
    if (module.examples) {
        library.addExamplesDir(module.name,module.examples.path);
    }
    nodeConfigCache = {};
}

```

It was an opportunity to get more familiar with a bit more of the node-red core.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [25 January 2021 20:40 UTC](https://discourse.nodered.org/t/opening-node-red/39665/13 "2021-01-25T20:40:25Z")

</div>

If you carefully and temporarily replace the `addModule` function in `C:\Users\Admin\AppData\Roaming\npm\node_modules\node-red\node_modules@node-red\registry\lib\registry.js` with my code above, you should find out what module is causing the issue.

You can leave the amended code in place, it will be replaced when Node-RED is next updated.

---

<div class="post-metadata">

**Author:** ![Mas](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Mas](https://discourse.nodered.org/u/Mas)\
**Post date:** [27 January 2021 10:36 UTC](https://discourse.nodered.org/t/opening-node-red/39665/14 "2021-01-27T10:36:10Z")

</div>

Thank you for your help and advice. Sorry, as I am new in node-red, I got confused.  
Now, I need to replace registery.js with your code addModule?  
registery.js code is very long, do I have to replace fully or a part of that?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [27 January 2021 21:00 UTC](https://discourse.nodered.org/t/opening-node-red/39665/15 "2021-01-27T21:00:21Z")

</div>

No, you only have to find the addModule function and replace it with mine.

BTW, if you get stuck or mess it up, don't panic. You can always just do `npm install node-red -g --unsafe-perm --production` to overwrite your changes with the original.

---

<div class="post-metadata">

**Author:** ![Mas](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Mas](https://discourse.nodered.org/u/Mas)\
**Post date:** [28 January 2021 08:49 UTC](https://discourse.nodered.org/t/opening-node-red/39665/16 "2021-01-28T08:49:26Z")

</div>

I appreciate your help. I have done that and I faced some errors in registery.js.  
for instance

 ![111](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/3/d3bc5a8a8f701c700cb98803140a1e8fffa819de.png)

**when I run node-red, I received this:**  
C:\Users\Admin\>node-red  
28 Jan 09:41:07 - [info]

# Welcome to Node-RED

28 Jan 09:41:07 - [info] Node-RED version: v1.2.7  
28 Jan 09:41:07 - [info] Node.js version: v14.15.4  
28 Jan 09:41:07 - [info] Windows\_NT 10.0.19041 x64 LE  
28 Jan 09:41:08 - [info] Loading palette nodes  
28 Jan 09:41:11 - [info] Dashboard version 2.25.0 started at /ui  
28 Jan 09:41:11 - [warn] ------------------------------------------------------  
28 Jan 09:41:11 - [warn] [node-red-contrib-netio/sample] Type not defined - check node definition  
28 Jan 09:41:11 - [warn] ------------------------------------------------------  
28 Jan 09:41:11 - [warn] Missing node modules:  
28 Jan 09:41:11 - [warn] - node-red-contrib-simpletime (2.10.0): simpletime  
28 Jan 09:41:11 - [warn] - node-red-contrib-homekit-abc (0.0.26): hassbian-abc-homekit-bridge, hassbian-abc-homekit-broadlink-mp1, hassbian-abc-homekit-windowCovering, hassbian-abc-homekit-midehumidifier, hassbian-abc-homekit-mihumidifier, hassbian-abc-homekit-haier-airbox, hassbian-abc-homekit-yeelight, hassbian-abc-homekit-miheater, hassbian-abc-homekit-camera, hassbian-abc-homekit-irmqtttv, hassbian-abc-homekit-mqttAC, hassbian-abc-homekit-qlwzdc1, hassbian-abc-homekit-zdc1, hassbian-abc-homekit-zm1, hassbian-abc-homekit-ztc1  
28 Jan 09:41:11 - [warn] - node-red-contrib-contextbrowser (0.0.4): contextbrowser, contextbrowser-sidebar  
28 Jan 09:41:11 - [warn] - node-red-contrib-modbus (5.13.3): modbus-client, modbus-response, modbus-read, modbus-getter, modbus-flex-getter, modbus-write, modbus-flex-write, modbus-server, modbus-flex-server, modbus-queue-info, modbus-flex-connector, modbus-io-config, modbus-response-filter  
28 Jan 09:41:11 - [warn] - node-red-contrib-cpu (0.0.4): cpu  
28 Jan 09:41:11 - [warn] - node-red-contrib-johnny5 (0.50.0): gpio in, gpio out, ioplugin, script  
28 Jan 09:41:11 - [warn] - node-red-contrib-tplink (1.0.0): kasa  
28 Jan 09:41:11 - [warn] - node-red-contrib-hs100 (0.4.0): hs100  
28 Jan 09:41:11 - [warn] - node-red-contrib-dlink-dspw (1.0.1): dsp-w215  
28 Jan 09:41:11 - [warn] - node-red-contrib-virtualmeter (0.5.28): virtualmeter, summeter, loadprediction, pvprediction, sumprediction, simplegsi  
28 Jan 09:41:11 - [warn] - node-red-contrib-homeseer (1.0.5): hs-server, hs-device, hs-event  
28 Jan 09:41:11 - [warn] - node-red-contrib-homekit (0.2.1): homekit-service, homekit-accessory  
28 Jan 09:41:11 - [warn] - node-red-contrib-net-ping (1.0.0): net-ping-node  
28 Jan 09:41:11 - [warn] - node-red-contrib-uibuilder (3.0.1): uibuilder  
28 Jan 09:41:11 - [warn] - node-red-contrib-blockly (1.1.0): Blockly  
28 Jan 09:41:11 - [warn] - node-red-contrib-timerswitch (1.3.0): timerswitch  
28 Jan 09:41:11 - [warn] - node-red-contrib-countdown (1.3.1): countdown  
28 Jan 09:41:11 - [warn] - node-red-contrib-toggle (0.1.1): toggle  
28 Jan 09:41:11 - [warn] - node-red-contrib-image-output (0.6.2): image  
28 Jan 09:41:11 - [warn] - node-red-contrib-hello-world (0.0.5): hello-world  
28 Jan 09:41:11 - [info] Removing modules from config  
28 Jan 09:41:11 - [info] Settings file : C:\Users\Admin.node-red\settings.js  
28 Jan 09:41:11 - [info] Context store : 'default' [module=memory]  
28 Jan 09:41:11 - [info] User directory : \Users\Admin.node-red  
28 Jan 09:41:11 - [warn] Projects disabled : editorTheme.projects.enabled=false  
28 Jan 09:41:11 - [info] Flows file : \Users\Admin.node-red\flows\_DESKTOP-GC83620.json  
28 Jan 09:41:11 - [info] Server now running at [http://127.0.0.1:1880/](http://127.0.0.1:1880/)  
28 Jan 09:41:11 - [warn]

* * *

Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials  
file will not be recoverable, you will have to delete it and re-enter  
your credentials.

## You should set your own key using the 'credentialSecret' option in your settings file. Node-RED will then re-encrypt your credentials file using your chosen key the next time you deploy a change.

28 Jan 09:41:11 - [info] Waiting for missing types to be registered:  
28 Jan 09:41:11 - [info] - modbus-client  
28 Jan 09:41:11 - [info] - Blockly  
28 Jan 09:41:11 - [info] - countdown  
28 Jan 09:41:11 - [info] - toggle

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [28 January 2021 19:57 UTC](https://discourse.nodered.org/t/opening-node-red/39665/17 "2021-01-28T19:57:03Z")

</div>

> [@Mas](#):
>
> [node-red-contrib-netio/sample] Type not defined - check node definition

There you go, that is the issue.

---

<div class="post-metadata">

**Author:** ![Mas](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Mas](https://discourse.nodered.org/u/Mas)\
**Post date:** [28 January 2021 22:10 UTC](https://discourse.nodered.org/t/opening-node-red/39665/18 "2021-01-28T22:10:58Z")

</div>

> [@Mas](#):
>
> node-red-contrib-netio

Great. Could you please tell me how to resolve this issue?

Actually, I was trying to create a node, I followed the document in this website [Creating Nodes : Node-RED](https://nodered.org/docs/creating-nodes/)  
basically, we should use " `node-red-contrib-"` as a prefix to name. which I called it " node-red-contrib-netio". I have started with a simple example of showing the text. Because I was amateur in this field.  
I have done all steps and I have added the node in the node-red library. it was added in the library, however, when I search it to install in the node-red, it was not found.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [28 January 2021 23:25 UTC](https://discourse.nodered.org/t/opening-node-red/39665/19 "2021-01-28T23:25:48Z")

</div>

> [@Mas](#):
>
> Great. Could you please tell me how to resolve this issue?

Is that your node? Or someone else's?

If it is yours, you need to go back to the docs to read again all of the things you need to do to have a successful custom node. In this case, the node called "sample" is missing the node type definition.

If it is not your node, you need to contact the node's author.

---

<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:** [29 January 2021 00:36 UTC](https://discourse.nodered.org/t/opening-node-red/39665/20 "2021-01-29T00:36:45Z")

</div>

@Mas I see you have indeed published your node to the library - [node-red-contrib-netio (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-netio)

We generally ask that people don't publish nodes to the library until they have been tested and are working. Given you knew this node wasn't working, then publishing it to npm and the library wasn't ideal.

Looking at your node, it is missing the node's `.html` file - as described in the docs you said you followed: [Creating your first node : Node-RED](https://nodered.org/docs/creating-nodes/first-node#lower-casehtml)

[Next page](https://discourse.nodered.org/t/opening-node-red/39665.md?page=2)
