# How to declare a local node for testing inside a folder level node-red instance?

**URL:** <https://discourse.nodered.org/t/how-to-declare-a-local-node-for-testing-inside-a-folder-level-node-red-instance/77404>\
**Category:** Developing Nodes\
**Created:** [10 April 2023 06:58 UTC](https://discourse.nodered.org/t/how-to-declare-a-local-node-for-testing-inside-a-folder-level-node-red-instance/77404 "2023-04-10T06:58:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![distante](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/distante/32/78684_2.png) [@distante](https://discourse.nodered.org/u/distante)\
**Post date:** [10 April 2023 06:58 UTC](https://discourse.nodered.org/t/how-to-declare-a-local-node-for-testing-inside-a-folder-level-node-red-instance/77404/1 "2023-04-10T06:58:31Z")

</div>

I am trying to set up a repository to create a custom node.

Since I want to share this repo between machines (with different OS), including the flows and custom nodes, I want to configure `node-red` to run locally from the repository's `node_modules` instead of installing it globally.

I have declared node-red as a dependency:

```auto
  "dependencies": {
    "@types/node-red": "^1.3.0"
  },
  "devDependencies": {
    "mocha": "^10.2.0",
    "node-red": "^3.0.2",
    "node-red-node-test-helper": "^0.3.0"
  }

```

and I have a script to start node-red there.

```auto
  "scripts": {
    "node-red": "npx node-red --settings ./node-red-files/settings.js --userDir ./node-red-files/user-dir"
  },

```

As per [this answer](https://stackoverflow.com/a/62954090/1255819), inside of `/user-dir/` I have created a symlink to a `nodes` folder that contains my custom node `js` and `html` file.

```auto
/node-red-files 
    /user-dir
        /nodes --> ../../nodes
/nodes 
     - custom-node.js 
     - custom-node.html

```

node red starts successfully but the custom node is not visible. I am missing something?

Thank you very much!

Edit: BTW I would also be open to achieve this using docker / docker-compose

---

<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:** [10 April 2023 10:48 UTC](https://discourse.nodered.org/t/how-to-declare-a-local-node-for-testing-inside-a-folder-level-node-red-instance/77404/2 "2023-04-10T10:48:46Z")

</div>

For a vanilla, non-docker solution, I think you are on the right lines. Maybe have a look at the alternate installer repo on my GitHub for ideas though, that presents a way of quickly creating local installed instances of node-red with a userDir that is contained within the master node-red folder so everything is in 1 place.

If you wanted to share a locally developed node into an instance, it is better to make sure that the node's folder has a proper package.json file. Then you can "install" it with `npm install `/nodes/mynode` or wherever you've put it (in its own sub-folder). That lets npm and node.js manage things for you.

---

<div class="post-metadata">

**Author:** ![distante](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/distante/32/78684_2.png) [@distante](https://discourse.nodered.org/u/distante)\
**Post date:** [10 April 2023 13:12 UTC](https://discourse.nodered.org/t/how-to-declare-a-local-node-for-testing-inside-a-folder-level-node-red-instance/77404/3 "2023-04-10T13:12:21Z")

</div>

Thak you for your answer!

I have found out in the mid-time that what is failing silently on my end is the `require` that `localFileSystem` does

node\_modules/@node-red/registry/lib/localfilesystem.js

```auto
 const pkg = require(packagefile) // <-- this fails

        result.package = pkg
        if(result.package) {
            result.allowed = true
            result.isPackage = true
            result.isNodeRedModule = typeof result.package['node-red'] === 'object'
            if(result.isNodeRedModule) {
                result.isNodeRedModule = true;
                result.allowed = registryUtil.checkModuleAllowed(pkg.name,pkg.version,loadAllowList,loadDenyList)
            }
        }

```

it throws a `MODULE_NOT_FOUND` error which node-red ignores.

I already did an npm `install ./nodes/my-node` but looks like it did not fix anything. (the package was copied to the repo root node\_modules)  
Besides that, I think `npm install` is not the best way if I want to keep the source code and the deployed node in sync. 🤔

---

<div class="post-metadata">

**Author:** ![distante](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/distante/32/78684_2.png) [@distante](https://discourse.nodered.org/u/distante)\
**Post date:** [10 April 2023 13:35 UTC](https://discourse.nodered.org/t/how-to-declare-a-local-node-for-testing-inside-a-folder-level-node-red-instance/77404/4 "2023-04-10T13:35:10Z")

</div>

The first error was fixed, I needed to set a complete path to my `./nodes` folder.

I set it on `settings.js` in this way:

```js
nodesDir: path.join(__dirname, '..', 'nodes');

```

The next error happens here:

```js
set.types.forEach(function(t) { // <---
                    if (nodeTypeToId.hasOwnProperty(t)) {
                        set.err = new Error("Type already registered");
                        set.err.code = "type_already_registered";
                        set.err.details = {
                            type: t,
                            moduleA: getNodeInfo(t).module,
                            moduleB: set.module
                        }

                    }
                });

```

my set does not have any `types` (it is undefined) I have no idea how to set it up 👀

---

<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:** [10 April 2023 16:20 UTC](https://discourse.nodered.org/t/how-to-declare-a-local-node-for-testing-inside-a-folder-level-node-red-instance/77404/5 "2023-04-10T16:20:27Z")

</div>

> [@distante](#):
>
> Besides that, I think `npm install` is not the best way if I want to keep the source code and the deployed node in sync.

I use it constantly. My dev PC runs Node-RED under PM2 and I use its watch function to watch for changes to any files/folders that need a Node-RED restart. So I can edit my custom nodes and each change saved triggers a restart of Node-RED.

> [@distante](#):
>
> my set does not have any `types` (it is undefined) I have no idea how to set it up

The type is defined in the modules package.json file. Details are in the node-red docs.

---

<div class="post-metadata">

**Author:** ![distante](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/distante/32/78684_2.png) [@distante](https://discourse.nodered.org/u/distante)\
**Post date:** [10 April 2023 17:04 UTC](https://discourse.nodered.org/t/how-to-declare-a-local-node-for-testing-inside-a-folder-level-node-red-instance/77404/6 "2023-04-10T17:04:10Z")

</div>

I found out the problem!

I had to remove the package.json file contained in my `./nodes` folder

> [@TotallyInformation](#):
>
> I use it constantly. My dev PC runs Node-RED under PM2 and I use its watch function to watch for changes to any files/folders that need a Node-RED restart. So I can edit my custom nodes and each change saved triggers a restart of Node-RED.

Yes, this is a good idea, It being so long since I used a watch. I will try it 🙂

---

<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:** [24 April 2023 17:04 UTC](https://discourse.nodered.org/t/how-to-declare-a-local-node-for-testing-inside-a-folder-level-node-red-instance/77404/7 "2023-04-24T17:04:20Z")

</div>

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