Start node application with debug on a fixed port OR auto attach multiple debuggers
When I run a node js application, which doesn't have a web UI part, IDE start the process with random port number. each time. Indicated by --debug-brk parameter inserted when run in a debug mode.
/usr/local/opt/node/bin/node --debug-brk=61921 --expose_debug_as=v8debug <path to js file> <application specific parameters>
The application I am working on can spins up one or more child processes, which are available for the debugger to attach.
Currently IDE debugger attached to the master process, but the child process is still waiting for the debugger to get attached to.
I can attach a remote debugger with a localhost and a port number, and save that as one of the configuration. However because port number changes all the time, it is not very useful.
So I am looking for an answer to see if it it possible,
A) Either stat the node debug process on fixed port (specified by the user), so the next child process would have a predictable port number.
B) Auto attach another instance of debugger to a child process.
I tried specifying the --debug-brk=<my port number> but it didn't work. The effective command generated for the debug mode, there were 2 --debug-brk arguments. Which makes things confusing for the node and IDE as well.
I am using intellij Ultimate edition with node.js (and some other) plugins.
Please sign in to leave a comment.
You can't start debugger on a fixed port. But, when using Node.js run configuration, each child process is available as a separate thread in Frames tab, and you can switch between them when debugging:
I think I might be missing something here. I can attach to the master process, however I don't see debugger getting attached to the forked child process. I do see the following messages
debugger listening on port 51874 <-- Master process
debugger listening on port 51875 <---Worker process
Where breakpoints only work for master process, also child process only resumes after there a debugger attached to it (due to 'debugger' code in the project);
I can attach a remote debugger and that works. But how do I get IDE to handle it automatically?
what configuration do you use to debug your application? Node.js or Node.js Remote? In the latter case, you have to create separate configuration for each of your processes; but in the former case breakpoints in child processes should work out of the box; you just need to make sure that child process is forked with --debug-brk (for Node<=6.*) or --inspect (for Node 7+)
I am using standard Node.js based configuration to run and debug application. Running is not a problem. When I start application in a debug mode, using standard Node.js configuration, IDE does attach to the master process. However it doesn't attach to the worker process. Then to test my theory, I tried to attach the worker process using the remote debugger configuration and it works. So now master processes is debugged via Node.js and worker process is debugged via remote debugger.
I hate to admit, but the node version I am using is pretty old. 0.10.x
this.process = fork(settings.exec, settings.args, {'env': envCopy,
'silent': settings.silent,
'execArgv': settings.execArgv
});
Just checked - child processes debugging works fine with Node.js 6.x and 7.x, but it doesn't indeed work with Node.js 0.10.
Sorry, but it is very unlikely that any fixes can be expected here... Node.js V8 protocol has changed several times since Node 0.10 was released, we can't afford supporting all possible versions :(
Logged anyway, please feel free to vote: https://youtrack.jetbrains.com/issue/WEB-27150
Thank you for verifying the problem and providing an explanation. I guess I will have to use workarounds until the project is upgraded to use newer version of the node.js.