Beginner create a test node Circular dependency issue

I'm experimenting trying to learn how to create nodes with installing them locally with npm install on the package.json file.

For learning purposes & experimentation, I have very generic node called msg-recycler where at the moment I am just feeding some string data into it attempting to validate the data and return Boolean True or False on the node output for the message.topic.

This is the data inside the inject node selected as JSON that I am trying to validate key values only:

{"VAV1": "read 12345:2 analogInput 2",    
"VAV2": "read 12345:2 analogInput 1",   
 "VAV3": "read 12345:2 analogInput 1",    
"VAV4": "read 12345:2 analogInput 2",   
 "VAV5": "read 12345:2 analogInput 1",    
"VAV6": "read 12345:2 analogInput 2",    
"VAV7": "read 12345:2 analogInput 1",       
"VAV8": "read 12345:2 analogInput 1",       
"VAV9": "read 12345:2 analogInput 2",       
"VAV10": "read 12345:2 analogInput 1"}

the javascript file that installed with npm install is this:

module.exports = function (RED) {
    "use strict";
    function msgRecycler(config) {

        RED.nodes.createNode(this, config);
        var node = this;
        this.on('input', function (msg) {

        const validateRequestType = type =>
            ['read', 'write', 'release'].includes(type);

        const validatePointType = type =>
            ['analogInput', 'analogValue', 'binaryValue', 'binaryInput'].includes(type);

        // "read 12345:11 analogInput 1"
        const validate = str => {
            const [requestType, deviceAddress, pointType, pointAddress] = str.split(' ');
            return validateRequestType(requestType) && validatePointType(pointType);
        }

        const valid = Object.values(msg).every(validate);
            msg.payload = valid; //Boolean
            node.send(msg);
        });
    }
    RED.nodes.registerType("msgrecycling", msgRecycler);
};

Basically its validating the word in the string read (requestType) and analogInput (pointType) in the string "read 12345:2 analogInput 1" in the validate function, hopefully that makes sense. I am trying return Boolean in the Node msg.payload = valid; //Boolean

In the debug I get this returned, circular dependancy issue. Would anyone have any tips to try?

msg.payload : Object

object
_msgid: "342fbccf54e4904f"
payload: "[Circular ~]"
topic: ""

Any tips help not a lot of wisdom here...

What do you mean by that?

From what I have been reading its a way to test locally a package before its published to npm

No. Using npm install inside your source installs the packages listed in your package JSON.

To test your package before publishing to npm you go to your node-red folder and enter npm install path-to-your-source

I took a look at your code and at first glance it looks ok.

Where is your source files saved? You aren't developing inside of the node modules folder are you?

Typically you would have the source code somewhere like /home/fred/src/my-node

Then to install it from SRC...

cd ~/.node-red
npm install /home/fred/src/my-node

Got it thanks Steve. I was developing in the .node-red folder. Thanks for the tip I copied the folder contents to the desktop of this Ubuntu Desktop machine. So running:

ben@ben-HP-ProBook-6550b:~/Desktop/msg-recycling$ npm install /home/ben/Desktop/msg-recycling
npm WARN msg-recycling@0.0.1 No repository field.
npm WARN msg-recycling@0.0.1 No license field.

up to date in 0.428s
found 0 vulnerabilities

And then restarting Node Red and the flow I still get this same error.

image

1 Jan 10:59:04 - [info] Starting flows
1 Jan 10:59:04 - [info] Started flows
1 Jan 10:59:11 - [info] [debug:83848d23775d79e0]
{ _msgid: 'd8fae69ffa3c62cf', payload: [Circular], topic: '' }

All you have done here is install your node inside your node. Re-read what I said.

Ps I would do an npm remove before you install this in node-red.

Whoops, learning curve is high : ) I did the uninstall npm process. And again on the Desktop version where you pointed that out.

How does this look?

ben@ben-HP-ProBook-6550b:~/.node-red/node_modules$ npm install /home/ben/Desktop/msg-recycling
+ msg-recycling@0.0.1
added 1 package and audited 171 packages in 2.144s

4 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Still this issue:

1 Jan 11:17:57 - [info] Starting flows
1 Jan 11:17:57 - [info] Started flows
1 Jan 11:18:08 - [info] [debug:83848d23775d79e0]
{ _msgid: 'ff2f27ab3c6c0c64', payload: [Circular], topic: '' }

thanks any tips greatly appreciated....

Nope. Please re-read once more...

You are performing the npm install from inside ~/.node-red/node_modules

cd to ~/.node-red folder only - like I wrote.

I have everything uninstalled. Trying again... Thank you for you're patience.

ben@ben-HP-ProBook-6550b:~/.node-red$ npm install /home/ben/Desktop/msg-recycling
+ msg-recycling@0.0.1
added 1 package and audited 171 packages in 1.852s

4 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Still same:

1 Jan 11:26:58 - [info] Starting flows
1 Jan 11:26:58 - [info] Started flows
1 Jan 11:27:08 - [info] [debug:83848d23775d79e0]
{ _msgid: 'd642c31744fbb859', payload: [Circular], topic: '' }
1 Jan 11:27:09 - [info] [debug:83848d23775d79e0]
{ _msgid: 'dec087999014a292', payload: [Circular], topic: '' }

Ok, but at least now we know what/where your source code is and how to set up.

If you are running in a debugger you should pause and inspect the value being returned from your functions. If not, then use console.log to check your code.

E.g.

this.on('input', function (msg) {

    console.log("msg", msg);

    const validateRequestType = type =>
        ['read', 'write', 'release'].includes(type);

    const validatePointType = type =>
        ['analogInput', 'analogValue', 'binaryValue', 'binaryInput'].includes(type);

    // "read 12345:11 analogInput 1"
    const validate = str => {
        const [requestType, deviceAddress, pointType, pointAddress] = str.split(' ');
        const result = validateRequestType(requestType) && validatePointType(pointType);
        console.log(`validate('${str}')... `, result)
        return result
    }

    //const valid = Object.values(msg).every(validate);

    const values = Object.values(msg);
    console.log("values", values);
    const valid = values.every(validate)
    console.log("valid", valid);


    msg.payload = valid; //Boolean
    node.send(msg);
});