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

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:

  "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.

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

As per this answer, inside of /user-dir/ I have created a symlink to a nodes folder that contains my custom node js and html file.

/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

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.

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

 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. :thinking:

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:

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

The next error happens here:

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 :eyes:

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.

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

I found out the problem!

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

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

1 Like

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