# Programmatically add custom nodes from within existing express-app

**URL:** <https://discourse.nodered.org/t/programmatically-add-custom-nodes-from-within-existing-express-app/95186>\
**Category:** Developing Nodes\
**Created:** [6 February 2025 15:03 UTC](https://discourse.nodered.org/t/programmatically-add-custom-nodes-from-within-existing-express-app/95186 "2025-02-06T15:03:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![WuerzburgerMaetschke](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wuerzburgermaetschke/32/98632_2.png) [@WuerzburgerMaetschke](https://discourse.nodered.org/u/WuerzburgerMaetschke)\
**Post date:** [6 February 2025 15:03 UTC](https://discourse.nodered.org/t/programmatically-add-custom-nodes-from-within-existing-express-app/95186/1 "2025-02-06T15:03:37Z")

</div>

Hello everyone,

In the last few days I have successfully integrated node-red into an existing express application.

Is there a way to add a custom node from this code base? So not by loading from a node folder from the user data directory?

I have tried the function: [Node-RED](https://nodered.org/docs/api/modules/v/1.3/@node-red_registry.html#.registerType)

I am also not quite sure how to integrate the html documents with scripts programmatically.

Why do I want to do that?  
I would like to access backend data in my custom nodes via existing repositories instances.

---

<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:** [6 February 2025 15:12 UTC](https://discourse.nodered.org/t/programmatically-add-custom-nodes-from-within-existing-express-app/95186/2 "2025-02-06T15:12:01Z")

</div>

Hi @WuerzburgerMaetschke

You cannot register a full node programmatically; we only support the runtime loading the nodes itself.

But, you can set the `nodesDir` setting you pass into the runtime to point at a directory on disk that contains the nodes you want to load. That can be within your application code, rather than the user directory. They will need to have a `package.json` file etc to 'appear' like a full node module.

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [6 February 2025 16:24 UTC](https://discourse.nodered.org/t/programmatically-add-custom-nodes-from-within-existing-express-app/95186/3 "2025-02-06T16:24:03Z")

</div>

To install custom nodes what I do is create tarballs i.e. npm packages and then import them into Node-RED using the same API that the upload tgz file uses:

 ![Screenshot 2025-02-06 at 17.18.47](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/e/4e0475eab85247cc6ed8f02f0a73045c139627ec.png)

the endpoint for that is a POST to `/nodes` with a single .tgz file as content. To verify that check your browser network traffic when doing a test upload.

That assumes that your embedding of Node-RED allows it to access that endpoint.

---

<div class="post-metadata">

**Author:** ![WuerzburgerMaetschke](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wuerzburgermaetschke/32/98632_2.png) [@WuerzburgerMaetschke](https://discourse.nodered.org/u/WuerzburgerMaetschke)\
**Post date:** [6 February 2025 17:49 UTC](https://discourse.nodered.org/t/programmatically-add-custom-nodes-from-within-existing-express-app/95186/4 "2025-02-06T17:49:38Z")

</div>

Ah, thx for the fast responses  
.  
I already switched to this path with the customized nodesDir, but i just wanted to check twice.  
I also need to adjust my webpack config for moving the files unbundled to the nodesDir output folder transpilled to js and copy the html files and package.json to the output folder, too.

@gregorius Thank you for this interesting idea. If I have understood it correctly, you simply install the custom nodes as a tarball at program start via the endpoint you mentioned.  
I might give it a try.

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [6 February 2025 18:05 UTC](https://discourse.nodered.org/t/programmatically-add-custom-nodes-from-within-existing-express-app/95186/5 "2025-02-06T18:05:51Z")

</div>

I use that endpoint to develop custom nodes in node red. Each update to a custom node is simple reinstalled and I can test my changes.

Be aware that the endpoint does version checking, so to reinstall a custom node that already exists the tarball needs a new version.

---

<div class="post-metadata">

**Author:** ![ch-zacmo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ch-zacmo/32/59923_2.png) [@ch-zacmo](https://discourse.nodered.org/u/ch-zacmo)\
**Post date:** [7 February 2025 08:53 UTC](https://discourse.nodered.org/t/programmatically-add-custom-nodes-from-within-existing-express-app/95186/6 "2025-02-07T08:53:27Z")

</div>

Hi,

When using nodesDir, can it contains multiple folder ? I created a custom node from the exemple [Creating your first node](https://nodered.org/docs/creating-nodes/first-node)

I tried nodesDir with the path to the folder containing my custom node folder and tried with the custom folder path directly and the node was nowhere to be found. I checked in the palette manager and nothing too.

Did I miss something ?

EDIT : I needed to 'npm install ./src/lib/red-nodes/test' in my main application to make it work. I thought this step was optional if I specified 'nodesDir'.

---

<div class="post-metadata">

**Author:** ![WuerzburgerMaetschke](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wuerzburgermaetschke/32/98632_2.png) [@WuerzburgerMaetschke](https://discourse.nodered.org/u/WuerzburgerMaetschke)\
**Post date:** [7 February 2025 12:11 UTC](https://discourse.nodered.org/t/programmatically-add-custom-nodes-from-within-existing-express-app/95186/7 "2025-02-07T12:11:30Z")

</div>

I had a path issue at the beginning, so i first set the path of the user directory, and noticed where my flows were saved to.  
something like:  
userDir: path.join(\_\_dirname, cfg.red.userDir),

gave me the correct locaiton i wanted instead of just my cfg.red.userDir path.

same worked then for my nodesDir.

---

<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:** [8 April 2025 12:12 UTC](https://discourse.nodered.org/t/programmatically-add-custom-nodes-from-within-existing-express-app/95186/8 "2025-04-08T12:12:01Z")

</div>

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