# Why searching only node\_modules?

**URL:** <https://discourse.nodered.org/t/why-searching-only-node-modules/89569>\
**Category:** Developing Nodes\
**Created:** [17 July 2024 11:12 UTC](https://discourse.nodered.org/t/why-searching-only-node-modules/89569 "2024-07-17T11:12:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![deostroll](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/deostroll/32/71472_2.png) [@deostroll](https://discourse.nodered.org/u/deostroll)\
**Post date:** [17 July 2024 11:12 UTC](https://discourse.nodered.org/t/why-searching-only-node-modules/89569/1 "2024-07-17T11:12:12Z")

</div>

Seeking comments from the team on node-red intended use/design.

Version used: 4.0.2  
Node-runtime - 20.14.0 & 18.x  
os: windows, linux

Steps:

1. Setup a new nodejs project and install node-red as dependency
2. Author a custom nr node inside project - location `nodes/cust-node1`. Files supplied further below. (Assets 1 & 2)
3. Added corresponding section in package.json for node-red to discover custom node. (Asset # 3)
4. Start node red using npx. (`npx node-red`)

Asset # 1 - **cust-node1.js**

```auto
module.exports = function(RED) {
    let delayArray = [5, 10, 12];
    let delayLength = delayArray.length;

    function CustNode1(config) {
        RED.nodes.createNode(this,config);
        var node = this;
        node.on('input', function(msg) {
            let idx = Math.floor(Math.random() * delayLength);
            let timeoutSeconds = delayArray[idx];
            setTimeout(() => {
                let payload = { timeoutSeconds };
                msg.payload = { ...msg.payload, ...payload };
                node.send(msg);
            }, timeoutSeconds * 1000);
        });
    }
    console.log('Node registered');
    RED.nodes.registerType("cust-node1",CustNode1);
}

```

Asset # 2 - **cust-node1.html**

```auto
<script type="text/javascript">
    RED.nodes.registerType('cust-node1',{
        category: 'function',
        color: '#a6bbcf',
        defaults: {
            name: {value:""}
        },
        inputs: 1,
        outputs: 1,
        // icon: "file.svg",
        label: function() {
            return this.name||"cust-node1";
        }
    });
</script>

<script type="text/html" data-template-name="cust-node1">
    <div class="form-row">
        <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
        <input type="text" id="node-input-name" placeholder="Name">
    </div>
</script>

<script type="text/html" data-help-name="cust-node1">
    <p>A simple node that adds a random delay in the flow to simulate something async</p>
</script>

```

Asset #3 - snippet that should go into **package.json**

```auto
  "node-red" : {
    "nodes": {
      "cust-node1": "nodes/cust-node1/cust-node1.js"
    }
  }

```

On starting node-red in manner mentioned above, the custom node does not get registered.

To workaround this issue I did the following:

1. copied `package.json` into the `node_modules` folder
2. modified the `"cust-node1": "nodes/cust-node1/cust-node1.js"` line in the package.json file to `"cust-node1": "../nodes/cust-node1/cust-node1.js"`
3. Started node-red in the manner above (using npx).

Narrowed down the issue to here: [node-red/packages/node\_modules/@node-red/registry/lib/localfilesystem.js at 4.0.2 · node-red/node-red · GitHub](https://github.com/node-red/node-red/blob/4.0.2/packages/node_modules/%40node-red/registry/lib/localfilesystem.js#L237-L247)

In this loop it misses checking out on the project's package.json

I don't understand why it was written that way.

💗&☮

---

<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:** [15 October 2024 11:12 UTC](https://discourse.nodered.org/t/why-searching-only-node-modules/89569/2 "2024-10-15T11:12:51Z")

</div>

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