Node for Max - Remote Debugging

Remote Debugging

When your program doesn’t run the way you expect, debugging is a powerful way to gain insight into your program’s behavior.

The easiest way to debug with node.script is with a remote debugger — a program that attaches to the Node script and provides a debugging interface. When node.script is run with debugging enabled, you will be able to set breakpoints in your code. If the program encounters a breakpoint while it’s running, it will pause and allow you to inspect the state of local variables and see the full function call stack.

In order to do remote debugging, you’ll need to choose an inspector client, and you’ll need to enable remote debugging for the node.script object in your Max patch. Options for inspector clients include the Google Chrome Browser, or an IDE like VS Code. For a full list refer to the official Node JS Guide on Debugging .

Enabling Remote Debugging

To enable remote debugging, you need to set command line options for the Node process that will be started by node.script. You can use the @options attribute of the node.script object to set those options.

There are two options for starting remote debugging, each of which has optional host and port parameter (host:port)

  1. --inspect[=[host:]port]
  2. --inspect-brk[=[host:]port]

The --inspect option simply enables the remote debugging capabilities on your Node Program and allows you to attach the debugger at any point.

By comparison, the --inspect-brk option “breaks” the program at startup, halts the execution, and waits for a remote debugger to attach itself and run the program. This can be useful when you are debugging code that runs at startup of the program.

Specifying a port when enabling debugging is optional — the default port is 9229.

Important: It is not recommended to enable remote debugging on a host other than 127.0.0.1 (localhost) in order to prevent others from attaching and executing code within your Node context.

For a detailed walkthrough on how to debug your node.script with the Google Chrome DevTools refer to the N4M-core-examples repository on Github ( https://github.com/Cycling74/n4m-core-examples ).

See Also

Name Description
Node for Max Documentation - Table of Contents Node for Max Documentation - Table of Contents
Node for Max - Debugging Node for Max - Debugging
node.script