# Beginner create a test node Circular dependency issue

**URL:** <https://discourse.nodered.org/t/beginner-create-a-test-node-circular-dependency-issue/55958>\
**Category:** Developing Nodes\
**Created:** [1 January 2022 15:32 UTC](https://discourse.nodered.org/t/beginner-create-a-test-node-circular-dependency-issue/55958 "2022-01-01T15:32:06Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbartling](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@bbartling](https://discourse.nodered.org/u/bbartling)\
**Post date:** [1 January 2022 15:32 UTC](https://discourse.nodered.org/t/beginner-create-a-test-node-circular-dependency-issue/55958/1 "2022-01-01T15:32:07Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/b/9b4866efed143f2a3e71b44a691d90ef38835e75.png)

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

```auto
{"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:

```auto
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?

```auto
msg.payload : Object

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

```

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 January 2022 16:09 UTC](https://discourse.nodered.org/t/beginner-create-a-test-node-circular-dependency-issue/55958/2 "2022-01-01T16:09:07Z")

</div>

> [@bbartling](#):
>
> installing them locally with `npm install` on the `package.json` file.

What do you mean by that?

---

<div class="post-metadata">

**Author:** ![bbartling](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@bbartling](https://discourse.nodered.org/u/bbartling)\
**Post date:** [1 January 2022 16:45 UTC](https://discourse.nodered.org/t/beginner-create-a-test-node-circular-dependency-issue/55958/3 "2022-01-01T16:45:15Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/1/f1ff3e3600645ab5d2c6cbe4e616586f6f332b97.png)

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 January 2022 16:51 UTC](https://discourse.nodered.org/t/beginner-create-a-test-node-circular-dependency-issue/55958/4 "2022-01-01T16:51:25Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![bbartling](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@bbartling](https://discourse.nodered.org/u/bbartling)\
**Post date:** [1 January 2022 17:02 UTC](https://discourse.nodered.org/t/beginner-create-a-test-node-circular-dependency-issue/55958/5 "2022-01-01T17:02:45Z")

</div>

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:

```auto
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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/b/dbd7b4c307a38ebf21538f519f6178f79b93ed2c.png)

```auto
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: '' }

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 January 2022 17:06 UTC](https://discourse.nodered.org/t/beginner-create-a-test-node-circular-dependency-issue/55958/6 "2022-01-01T17:06:23Z")

</div>

> [@bbartling](#):
>
> ```auto
> ben@ben-HP-ProBook-6550b:~/Desktop/msg-recycling$ npm install /home/ben/Desktop/msg-recycling
> 
> ```

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.

---

<div class="post-metadata">

**Author:** ![bbartling](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@bbartling](https://discourse.nodered.org/u/bbartling)\
**Post date:** [1 January 2022 17:19 UTC](https://discourse.nodered.org/t/beginner-create-a-test-node-circular-dependency-issue/55958/7 "2022-01-01T17:19:06Z")

</div>

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?

```auto
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:

```auto
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....

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 January 2022 17:22 UTC](https://discourse.nodered.org/t/beginner-create-a-test-node-circular-dependency-issue/55958/8 "2022-01-01T17:22:05Z")

</div>

> [@bbartling](#):
>
> How does this look?
> 
> ```auto
> ben@ben-HP-ProBook-6550b:~/.node-red/node_modules$ npm install /home/ben/Desktop/msg-recycling
> 
> ```

Nope. Please re-read once more...

> [@Steve-Mcl](#):
>
> Then to install it from SRC...
> 
> ```auto
> cd ~/.node-red
> npm install /home/fred/src/my-node
> 
> ```

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

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

---

<div class="post-metadata">

**Author:** ![bbartling](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@bbartling](https://discourse.nodered.org/u/bbartling)\
**Post date:** [1 January 2022 17:30 UTC](https://discourse.nodered.org/t/beginner-create-a-test-node-circular-dependency-issue/55958/9 "2022-01-01T17:30:10Z")

</div>

> [@bbartling](#):
>
> `npm install /home/ben/Desktop/msg-recycling`

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

```auto
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:

```auto
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: '' }

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 January 2022 17:50 UTC](https://discourse.nodered.org/t/beginner-create-a-test-node-circular-dependency-issue/55958/10 "2022-01-01T17:50:31Z")

</div>

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.

```auto
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);
});

```

---

<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:** [2 March 2022 17:51 UTC](https://discourse.nodered.org/t/beginner-create-a-test-node-circular-dependency-issue/55958/11 "2022-03-02T17:51:10Z")

</div>

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