How to proper debug custom node

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...

  1. Install node-red as per instructions on nodered.org
  2. Run it one time so that .node-red folder is generated
  3. Install own node...
    1. cd c:\users\me\.node-red (or linux equivelant)
    2. npm install c:\path_to_my_node
  4. Open VS code & "open folder" created on step 2 e.g. c:\users\me\.node-red (or linux equivelant)
  5. Add following configuration to vscode launch.json (press CTRL+SHIFT+P then type launch.json)...
{
  "version": "0.2.0",
  "configurations": [
   
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Node-red",
      "program": "c:\\path_to_npm_global\\node-red\\red.js",
      "runtimeArgs": ["--preserve-symlinks", "--experimental-modules"],
      "env": {
        "NO_UPDATE_NOTIFIER": "1"
      }
    },
    {
      "type": "node",
      "request": "launch",
      "name": "Debug Current File",
      "program": "${file}"
    },
    { "type": "node", "request": "attach", "name": "Attach to Process", "processId": "${command:PickProcess}" } 
    
  ]
}
  1. Select "Launch Node-red" from the debug drop down & press F5

Hope this helps

Edit...
Some notes on my vs code setup

  • "NO_UPDATE_NOTIFIER": "1" Without this, node-red takes over 3 minute startup (corporate proxy issue)
  • --preserve-symlinks because npm install c:\folder\my_node creates a symlink & debug points wont stop on your .js code without it
3 Likes