# How to proper debug custom node

**URL:** <https://discourse.nodered.org/t/how-to-proper-debug-custom-node/9308>\
**Category:** General\
**Created:** [22 March 2019 10:07 UTC](https://discourse.nodered.org/t/how-to-proper-debug-custom-node/9308 "2019-03-22T10:07:52Z")\
**Posts on this page:** 3\
**Page:** 3

<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:** [21 February 2023 09:47 UTC](https://discourse.nodered.org/t/how-to-proper-debug-custom-node/9308/43 "2023-02-21T09:47:07Z")

</div>

ok, then this is how i do NR development on full source...

### Using a debug config

_where starting debug is as simple as pressing `F5`_

launch.json

```auto
{
    "version": "0.2.0",
    "configurations": [
        // add entry to launch.json to debug node-red
        {
            "type": "node",
            "request": "launch",
            "name": "debug node-red",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "env": { 
                "NODE_ENV": "development", 
                "port": "1881", 
            },
            "preLaunchTask": "npm: build-dev",
            "program": "${workspaceFolder}\\packages\\node_modules\\node-red\\red.js"
        }
    ]
}

```

##### You may also need to add a tasks.json

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/8/a81fb7cb9a17bf97302b4682c6019abceb924d39.png)

```auto
{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "npm",
			"script": "build-dev",
			"group": "build",
			"problemMatcher": [],
			"label": "npm: build-dev",
			"detail": "build-dev"
		}
	]
}

```

  

### Using the newer "Auto Attach" feature of VSCode

1. Open a terminal window inside vscode
2. set VSCode to use "Auto Attach: Always"
3. run `npm run dev`  
 ![Code_UFMjwrNzkq](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/1/91f465e23c6c84dc9cf4bcf5fd8040e375749aa0.gif)

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [21 February 2023 09:59 UTC](https://discourse.nodered.org/t/how-to-proper-debug-custom-node/9308/44 "2023-02-21T09:59:36Z")

</div>

> [@Steve-Mcl](#):
>
> ### Using a debug config
> 
> _where starting debug is as simple as pressing `F5`_
> 
> launch.json

That works 🙂  
The instance is running 🙂

I now just need to work out how to actually use VSCode - I've tried many times over the years to get to grips with it but always failed and given up and gone back to using chalk on a blackboard 🙂

[edit] Brilliant - I'm adding breakpoint and able to look at values - this should make things easier to see what's going on compared to sprinkling node.warns throughout the code:slight\_smile:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/55fcb7fb3578725ad74798fe3f13f2e65f60f34c.png)

I could really do with a dual monitor setup now though 🙂

[edit2] Wow - I feel like a proper dev - I'm like Neo in The Matrix - I can see the code! 😀

---

<div class="post-metadata">

**Author:** ![tve](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tve/32/59475_2.png) [@tve](https://discourse.nodered.org/u/tve)\
**Post date:** [21 February 2023 17:19 UTC](https://discourse.nodered.org/t/how-to-proper-debug-custom-node/9308/45 "2023-02-21T17:19:48Z")

</div>

> [@cymplecy](#):
>
> compared to sprinkling node.warns throughout the code

Nice that you got the debugger working!  
On the "sprinkling node.warns"... two tricks I use a lot:

- console.log(foo) prints foo as a data structure, so you can see what's inside (node.warn requires a string, i.e., applies toString(), which is not as helpful)
- `try { ... } catch(err) { console.log(err.stack) }` prints a stack trace if your code `...` throws so you know exactly where the exception happened (this is also useful in function nodes)

[Previous page](https://discourse.nodered.org/t/how-to-proper-debug-custom-node/9308.md?page=2)
