# Custom node require failure

**URL:** <https://discourse.nodered.org/t/custom-node-require-failure/39772>\
**Category:** Developing Nodes\
**Created:** [26 January 2021 11:49 UTC](https://discourse.nodered.org/t/custom-node-require-failure/39772 "2021-01-26T11:49:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![UnivSim](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/univsim/32/32286_2.png) [@UnivSim](https://discourse.nodered.org/u/UnivSim)\
**Post date:** [26 January 2021 11:49 UTC](https://discourse.nodered.org/t/custom-node-require-failure/39772/1 "2021-01-26T11:49:01Z")

</div>

Hi,

I'm writing a custom node for Node-red (see versions below) but i require other modules/scripts in it.  
When i add the require line (see my code) it failes to show up in the node-red brwoser interface. when i comment out the require lines i can see my node.  
Ofcorse my node doesn't work as it requires the GPIO package...

What am i doing wrong?

the 'error' code:  
26 Jan 12:40:30 - [info] Waiting for missing types to be registered:  
26 Jan 12:40:30 - [info] - input-test

My code (JS)

```auto
module.exports = function(RED) {

    const CAN = require('mcpreadwrite');
    const SPI = require('spi-device');
	const gpiop = require('rpi-gpio').promise;
	//const gpiop = require('rpi-gpio').promise;

   function INPUTTEST(config) {
        RED.nodes.createNode(this,config);
		//this.on('input', function(msg) {
		//	
		//	this.send(msg);
		//});
		
		gpiop.setup(config.pin, gpiop.DIR_IN, gpiop.EDGE_BOTH);
		gpiop.on('change', function(channel, value) {
			msg.payload = value;			
			this.send(msg);
		});
    }
    RED.nodes.registerType("input-test", INPUTTEST);
}

```

HTML:

```auto
<script type="text/javascript">
    RED.nodes.registerType('input-test',{
        category: 'US_Input',
        color: '#38F6F6',
        defaults: {
			pin: {value:0}
        },        
        outputs:1,
        icon: "serial.png",
        label: "input-test"
    });
</script>

<script type="text/x-red" data-template-name="input-test">
    <div class="form-row">
		<label for="node-input-pin"><i class="icon-tag"></i>Pin</label>
		<input id="node-input-pin">
    </div>
</script>

<script type="text/x-red" data-help-name="input-test">
    <p>Unwritten</p>
</script>

```

JSON:

```auto
{
  "name": "input",
  "version": "1.0.0",
  "description": "Controll the US-Input cart",
  "main": "input.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "mcpreadwrite": "file:../MCP2515-ReadWrite",
    "rpi-gpio": "^2.1.7",
    "spi-device": "^3.1.0"
  },
  "node-red": {
    "nodes": {
      "main": "input.js"
    }
  }
}

```

NPM version: 6.14.10  
Node.jS version: v12.20.1  
Node-Red version: v1.2.6  
Running on a RPi 3B+: Linux version 5.4.79-v7+ (dom@buildbot) (gcc version 8.4.0 (Ubuntu/Linaro 8.4.0-3ubuntu1))

Edit reason: added OS

---

<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:** [26 January 2021 12:06 UTC](https://discourse.nodered.org/t/custom-node-require-failure/39772/2 "2021-01-26T12:06:29Z")

</div>

Are the `require`d modules installed?

If you are able to step debug (e.g. in VScode) the put the keyword `debugger` before the require.

This might help...

> [@How to proper debug custom node](https://discourse.nodered.org/t/how-to-proper-debug-custom-node/9308/13):
>
> This is how I debug a custom node in VS Code... It works for me however since this is a dist version of node-red its difficult sometimes to debug client side issues. Other than that, debug stop points work in my node js files. For debuging my .html files, i enter debugger into the function & open F12 (chrome debugger stops on the debugger statement) Setup... Install node-red as per instructions on [nodered.org](http://nodered.org) Run it one time so that .node-red folder is generated Install own node... cd c:…

---

<div class="post-metadata">

**Author:** ![UnivSim](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/univsim/32/32286_2.png) [@UnivSim](https://discourse.nodered.org/u/UnivSim)\
**Post date:** [26 January 2021 12:24 UTC](https://discourse.nodered.org/t/custom-node-require-failure/39772/3 "2021-01-26T12:24:26Z")

</div>

Hi steve,

Thanks for your reply.  
to the first question: Yes required nodes are installed in the correct place.  
I'll have to take a look in the debugger but don't know how it works . (lets find out 🙂 )

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [26 January 2021 13:08 UTC](https://discourse.nodered.org/t/custom-node-require-failure/39772/5 "2021-01-26T13:08:38Z")

</div>

A more immediate step forward would be to wrap your `require()` statements in a try/catch block to see what error is actually being reported:

```auto
try {
   const CAN = require('mcpreadwrite');
   const SPI = require('spi-device');
   const gpiop = require('rpi-gpio').promise;
} catch(err) {
   console.log(err);
   throw err;
}
```
