# Custom Node Error missing types

**URL:** https://discourse.nodered.org/t/custom-node-error-missing-types/24379
**Category:** General
**Created:** [7 April 2020 07:33 UTC](https://discourse.nodered.org/t/custom-node-error-missing-types/24379 "2020-04-07T07:33:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Iliyas](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iliyas/32/19045_2.png) [@Iliyas](https://discourse.nodered.org/u/Iliyas)
#### Post date: [7 April 2020 07:33 UTC](https://discourse.nodered.org/t/custom-node-error-missing-types/24379/1 "2020-04-07T07:33:31Z")

</div>

Hello All,  
I have created a custom node and I have deployed it successfully it is working fine but now I have some done some changes in my node.js code and I have replaced my previous custom node code with this code but now it is throwing some error

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

The above image will show the error occurred will running node-red.

---

<div class="post-metadata">

### Author: ![Iliyas](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iliyas/32/19045_2.png) [@Iliyas](https://discourse.nodered.org/u/Iliyas)
#### Post date: [7 April 2020 07:34 UTC](https://discourse.nodered.org/t/custom-node-error-missing-types/24379/2 "2020-04-07T07:34:25Z")

</div>

```auto
module.exports = function(RED) {
	
	var WebSocket = require('ws');
	//var Stomp = require('stompjs');
	
    function CustomWebSocketListener(config) {
        RED.nodes.createNode(this,config);
        var node = this;
        node.on('input', function(msg) {
			
			let msg =msg.payload;
			let urllist = msg.url;
			let urls=[]
					
			if(global.websocket!=null || global.websocket!=undefined){
				let connections=global.websocket;
				console.log("global")
				if(isAccessTokenExpired){
					for(let k in connections) {
					   connections[k].close();
					   connections[k].reconnect=false
					   console.log('connection closed:::');
					}
					urls=urllist;
				}
				else{
					for(let i=0;i<urllist.length;i++){
					  let group=urllist[i].split("/")[7].split("?");
					  if(!connections[group[0]]){
						 urls.push(urllist[i])
					  }
					}
				}
			}
			else{
				urls=urllist;
			}
			
			console.log("urls.length::::"+urls.length)
			if(urls.length > 0){
							for(let i=0;i<urls.length;i++){
							console.log(':::::::for loop:::::::')
							console.log('url----'+urls[i])
							function connect(urlIndex) {
								let ws;
								if(urlIndex!=undefined||urlIndex!=null){
									ws = new WebSocket(urls[urlIndex]);
								}
								else{
									ws = new WebSocket(urls[i]);	
								}
								ws.index=i;
								ws.reconnect=true;
								ws.onopen = function() {
									
								};

							  ws.onmessage = function(e) {
								console.log('Message:', e.data);
								//var data=JSON.parse(e.data);
								  //msg.payload=data;
								 // var data=JSON.stringify(e.data);
								  //console.log(" **********8dataaaaa*****")
								  //console.log(data)
								// var error_1="{\"subscriptionTerminated\":{\"reason\":{\"messageId\":\"POL0014\",\"text\":\"Token Validation Error. Code %1, Required Scopes %2\",\"variables\":[\"TE0004\",\"msi_unsapi_location.watch\"]}}}";
								  //console.log(" ***********string***********",+data);
								// if(data==error_1)
									 // {
										//console.log(" *********if*****")
										//node.send({payload:data});
										//var token_value="Token Expired";
										//node.send({payload:token_value});
										
									  //}
								//else{
									//console.log(" *********else*****")
									
									
									/*msg.payload=e.data;
									var log="Connected";
									// msg.payload=log;
									node.send({payload:log});
									node.send(msg);
									*/
									
								//}
								};

							  ws.onclose = function(e) {
								  var dis="Disconnected";
								//	node.send({payload:dis})
								  var log_1="Socket is closed. Reconnect will be attempted in 30 second.";
								  //msg.payload=log_1;
								 // node.send({payload:log_1});
								console.log('Socket is closed. Reconnect will be attempted in 30 second.', e.reason);
								setTimeout(function() {
									console.log("onclose ----ws reconnect"+ws.reconnect)
									if(ws.reconnect){
										console.log("inside if reconnect")
									connect(ws.index);
									}
								}, 30000);
							  };

							  ws.onerror = function(err) {
								console.error('Socket encountered error: ', err.message, 'Closing socket');
								ws.close();
							  };
							 if(global.websocket==null || global.websocket==undefined){
								 global.websocket={};
								 console.log(global.websocket)
								 global.websocket[urls[i]]=ws;
							 }
							 else{
								 global.websocket[urls[i]]=ws;
							 }
							}
							connect();
							
							}
			
			}
			
		
        });
    }
    RED.nodes.registerType("custom-websocketlistener",CustomWebSocketListener);
}

```

The above code is what I have changed

---

<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: [6 June 2020 07:34 UTC](https://discourse.nodered.org/t/custom-node-error-missing-types/24379/3 "2020-06-06T07:34:26Z")

</div>

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