# Async registerType callback?

**URL:** <https://discourse.nodered.org/t/async-registertype-callback/97081>\
**Category:** Developing Nodes\
**Created:** [15 May 2025 15:07 UTC](https://discourse.nodered.org/t/async-registertype-callback/97081 "2025-05-15T15:07:53Z")\
**Posts on this page:** 10\
**Page:** 1

<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:** [15 May 2025 15:07 UTC](https://discourse.nodered.org/t/async-registertype-callback/97081/1 "2025-05-15T15:07:54Z")

</div>

I might be a bit thick today but I don't seem to be able to find any magic to allow the `RED.nodes.registerType` callback function to be an async function?

I have a function call in it that I would ideally like to `await` and that has to be async.

The only other approach is a major re-write to push all of the follow-up processing into a promise `.then()` which is fairly horrible and hard to follow.

Anyone have any other ideas?

---

<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:** [15 May 2025 15:14 UTC](https://discourse.nodered.org/t/async-registertype-callback/97081/2 "2025-05-15T15:14:52Z")

</div>

Sheesh! And isn't that typical. Immediately after I posted this, I worked it out!

You simply add an IIFE wrapper.

```js
// ...
(async () => {
    try {
        await someAsyncPromisesFn()
    } catch (e) {
        log.error('It failed you numpty!`, e)
    }
})()
// ...

```

I've been trying to work that out for ages! 😃

Of course, the outer function keeps going and doesn't wait - but in this case, that is fine as everything will be complete before the instance setup completes.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [15 May 2025 15:17 UTC](https://discourse.nodered.org/t/async-registertype-callback/97081/3 "2025-05-15T15:17:42Z")

</div>

You numpty!!

\<is the code I’m reading\> 😁

---

<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:** [15 May 2025 15:18 UTC](https://discourse.nodered.org/t/async-registertype-callback/97081/4 "2025-05-15T15:18:09Z")

</div>

Yup, that's how I feel right now! 👍

---

<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:** [15 May 2025 15:25 UTC](https://discourse.nodered.org/t/async-registertype-callback/97081/5 "2025-05-15T15:25:34Z")

</div>

I'm trying to dig myself out of a different hole I created when I set up uibuilder's templating system.

I allowed for external templates but I didn't allow for a "standard" template to be external, only internal. Over time that has come back to haunt me as some of the templates are examples of using front-end frameworks.

As we know, FE frameworks drift over time and now, trying to maintain them within the uibuilder module has become increasingly burdensome. So I want to dump them out but I still want to have a list people can refer to.

That means firstly - simplifying the template setup. Then adapting the setup function. It has to be async because the external part relies on `degit` which is purely async.

Once I can do this, I can easily update the more complex templates and have even more readily available showing more complex examples and including more integrated build tools and the like.

---

<div class="post-metadata">

**Author:** ![AllanOricil](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/allanoricil/32/106911_2.png) [@AllanOricil](https://discourse.nodered.org/u/AllanOricil)\
**Post date:** [15 May 2025 19:38 UTC](https://discourse.nodered.org/t/async-registertype-callback/97081/6 "2025-05-15T19:38:06Z")

</div>

Can you share your solution? I did not see any registerType with a callback yet

Client registration:

> <https://github.com/AllanOricil/node-red-vue-inputs-experiments/blob/main/src%2Findex.client.ts>

Server registration:

> <https://github.com/AllanOricil/node-red-vue-inputs-experiments/blob/main/src%2Findex.server.ts>

---

<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:** [15 May 2025 19:51 UTC](https://discourse.nodered.org/t/async-registertype-callback/97081/7 "2025-05-15T19:51:38Z")

</div>

> [@AllanOricil](#):
>
> Can you share your solution? I did not see any registerType with a callback yet

> <https://github.com/TotallyInformation/node-red-contrib-uibuilder/blob/main/nodes/uibuilder/uibuilder.js#L157>

All of my nodes follow the same format. The 2nd parameter of `RED.nodes.registerType` references a function and it is that function that I wanted to make async. But if I try, the node won't load. It is that function that is run when an instance of your node is deployed in a flow.

I've worked around the issue by using an IIFE wrapped around an async section because I didn't actually need the whole fn to be async in the end.

---

<div class="post-metadata">

**Author:** ![AllanOricil](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/allanoricil/32/106911_2.png) [@AllanOricil](https://discourse.nodered.org/u/AllanOricil)\
**Post date:** [15 May 2025 20:16 UTC](https://discourse.nodered.org/t/async-registertype-callback/97081/8 "2025-05-15T20:16:02Z")

</div>

What is the goal with this pattern? You want to have the construction of all instances of the same node type running in series?

---

<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:** [15 May 2025 20:21 UTC](https://discourse.nodered.org/t/async-registertype-callback/97081/9 "2025-05-15T20:21:48Z")

</div>

> [@AllanOricil](#):
>
> You want to have the construction of all instances of the same node type running in series?

Sorry, not sure what you mean?

Every instance of a node MUST have its own settings and processing separate from every other node. Behind that independent instance process you have a common set of data and processes.

If you don't have an equivalent of what I call `nodeInstance` but many nodes have as an embedded function (which really isn't good practice), you can never have more than one set of settings shared between all instances of a node type.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/a/0a9cde2c7e2a1604e9fc127e2f6a9764ef788fa4.png)

In my nodes, I flatten the functional structure to make it easier to follow and to reduce the need for implied data inheritence.

My testbed node module is probably easiest to follow:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/c/7c050b912bb2c9910f8313c03d6711cd060cc26d.png)

> **[GitHub - TotallyInformation/uib-template-test: This is a test external template for...](https://github.com/TotallyInformation/uib-template-test)**
>
> This is a test external template for node-red-contrib-uibuilder.

---

<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:** [14 July 2025 20:22 UTC](https://discourse.nodered.org/t/async-registertype-callback/97081/10 "2025-07-14T20:22:18Z")

</div>

Closed on 14 July 2025 20:22 UTC

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