# Custom node is not adding to Node-red

**URL:** <https://discourse.nodered.org/t/custom-node-is-not-adding-to-node-red/21475>\
**Category:** General\
**Created:** [10 February 2020 06:01 UTC](https://discourse.nodered.org/t/custom-node-is-not-adding-to-node-red/21475 "2020-02-10T06:01:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![VIKRAMAS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vikramas/32/3955_2.png) [@VIKRAMAS](https://discourse.nodered.org/u/VIKRAMAS)\
**Post date:** [10 February 2020 06:01 UTC](https://discourse.nodered.org/t/custom-node-is-not-adding-to-node-red/21475/1 "2020-02-10T06:01:48Z")

</div>

I have created the node-red custom node which will take the **URLs** to be connected and it connects to multiple endpoints dynamically.

Below is the code that I am using[package.json](https://discourse.nodered.org/uploads/short-url/hUepNLoJj9sZQUHBKZBKltD0xe5.json) (434 Bytes) [package-lock.json](https://discourse.nodered.org/uploads/short-url/vZluLS4xmCzIaq1QQkPzTrkG35Q.json) (669 Bytes) .

**HTML:**

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

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

<script type="text/html" data-help-name="websocketlistener">
    <p>Based on the input JSON urls it will listen from websocket multiple endpoint</p>
</script>

```

**JAVASCRIPT:**  
module.exports = function(RED) {

```
var WSCLIENT = require('ws-reconnect');

function CustomWebSocketListener(config) {
    RED.nodes.createNode(this,config);
    var node = this;
    node.on('input', function(msg) {
		
		let urls =msg.payload.urls;
		let connections = {};
		
		
			for(let i=0;i<urls.length;i++){
				if(connections[urls[i]]){
					
				}
				else{
				const wsclient = new WSCLIENT(urls[i],{
				retryCount:1, // default is 2
				reconnectInterval: 20 // default is 5
				});
				wsclient.start();
				wsclient.on("message",function(data){
					    node.send(msg);
    
				});

				wsclient.on("reconnect",function(){
					console.log("websocketlistener :::reconnecting");
				});
				wsclient.on("connect",function(){
					console.log("websocketlistener ::: connected"+urls[i]);
					wsclient.send(urls[i]);
				});
				wsclient.on("destroyed",function(){
					console.log("websocketlistener ::: destroyed");
				});
				connections[urls[i]]=wsclient;

				}
			}
		
	
    });
}
RED.nodes.registerType("websocketlistener",CustomWebSocketListener);

```

}

Below is the command I am using for linking node to node-red.

In custom node folder: `npm link node-red-contrib-websocketlistener`  
Then in node-red I ran the following command: `npm link "E:\node-red custom node\node-red-contrib-websocketlistener"`

But after the above steps also it is not adding in node-red.

---

<div class="post-metadata">

**Author:** ![alexk111](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alexk111/32/16891_2.png) [@alexk111](https://discourse.nodered.org/u/alexk111)\
**Post date:** [10 February 2020 09:09 UTC](https://discourse.nodered.org/t/custom-node-is-not-adding-to-node-red/21475/2 "2020-02-10T09:09:57Z")

</div>

- Created `websocketlistener.js` with the js code
- Created `websocketlistener.html` with the html code
- Added `"websocketlistener": "websocketlistener.js"` to the `node-red > nodes` in `package.json`.
- Restarted NR

The node appeared in Functions, so the code is ok. Probably something wrong with the `npm link` step.

---

<div class="post-metadata">

**Author:** ![alexk111](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alexk111/32/16891_2.png) [@alexk111](https://discourse.nodered.org/u/alexk111)\
**Post date:** [10 February 2020 09:16 UTC](https://discourse.nodered.org/t/custom-node-is-not-adding-to-node-red/21475/3 "2020-02-10T09:16:21Z")

</div>

Also [check this](https://discourse.nodered.org/t/node-not-shown-in-palette/21386/17)

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [10 February 2020 09:48 UTC](https://discourse.nodered.org/t/custom-node-is-not-adding-to-node-red/21475/4 "2020-02-10T09:48:09Z")

</div>

Have you tried installing it instead? Go to the node red user directory, often `~/.node-red/` or your platform’s equivalent, then running `npm install /path/to/folder/with/source`

---

<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 February 2020 17:45 UTC](https://discourse.nodered.org/t/custom-node-is-not-adding-to-node-red/21475/5 "2020-02-10T17:45:07Z")

</div>

Yes, please use a browser from at least this century 🙂 IE11 is no longer likely to work on many sites.

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [10 February 2020 18:52 UTC](https://discourse.nodered.org/t/custom-node-is-not-adding-to-node-red/21475/6 "2020-02-10T18:52:57Z")

</div>

Sadly, it's still required in a number of corporate environments. I remember when only a couple years ago we still had to test on both Edge and IE10/11 for a product because the client's had customers on either of those... It was great when we finally could drop IE10 from the tests, and upgrade the testing machine that had been kept back on purpose.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [10 February 2020 22:59 UTC](https://discourse.nodered.org/t/custom-node-is-not-adding-to-node-red/21475/7 "2020-02-10T22:59:29Z")

</div>

As this node code is under control of the OP - they can re-write it to use ES5 compatible javascript such that IE11 can render it correctly.

---

<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:** [10 April 2020 22:59 UTC](https://discourse.nodered.org/t/custom-node-is-not-adding-to-node-red/21475/8 "2020-04-10T22:59:35Z")

</div>

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