Remote debugging of Node for Max script

EHS UoS's icon

I'm trying to get my head around using the remote debugging feature of Node for Max, as described here:
https://docs.cycling74.com/max8/vignettes/10_n4m_remotedebug
I'm struggling as when I use the --inspect-brk option, the debugger I'm using (have tried Chrome DevTools and node-inspect CLI) drops me in to a file called " nsRunner.js ", not my test script as I would expect it to.
Adding "debugger;" statements in myscript also don't seem to be picked up when i continue from this initial breakpoint.
The documentation also says:

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

However I cant see any examples in this repo that refer to remote debugging at all. Am I missing something?

EDIT: I'm running on Windows 10, if that makes any difference.

Thanks,
Sam

EHS UoS's icon

In case anyone else stumbles accross this with a similar issue, it turns out that adding "debugger;" statements to the node script does work (I had placed them in a section of script that accidentally wasn't being called). By adding the "@option --inspect" argument to node.script and connecting via the command line using

node-inspect 127.0.0.1:9929

I was able to drop in at an appropriate point in my script for interactive debugging.

However, I believe correction of the documentation to link to the correct example is still needed.

Florian Demmer's icon

Hey there,

sorry for the slight delay. It seems like you actually got everything running and also the behaviour for --inspect-brk was in fact correct. nsRunner.js is the entry point to all scripts loaded via node.script. You can think of it as the shell that sets up things like IO, Error Handling and makes the max-api module available.

So basically when using --inspect-brk just continue from the debugger and you should be able to break and debug your scripts as expected once connected. So yeah, either --inspect-brk or --inspect should work and one might use either one according to your needs (as there are fe certain things on load etc that could be better handled with the former option).

I agree that it would be beneficial if we offered a more practical example on how to remote debug with Chrome and maybe even a more integrated editor like VSCode, which makes things even simpler. I'll keep you posted.

Thanks,
Florian

Arthur Parmentier's icon

Hey Florian, we definitively need an example to work with VS, I basically can't figure out how to make it!

mike w's icon

Create a launch.json, then click play in VS Code.

{
"name": "Attach to Process",
"type": "node",
"request": "attach",
"port": 9229
}

check out : Setting up an "Attach" configuration
https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_setting-up-an-attach-configuration