CLI option to attach debugger to a port
I've implemented a library that makes spawning a debugger for node applications extremely easy.
However, chrome does not allow opening chrome-devtools:// urls on launch - the user has to manually paste it into the address bar.
It would be awesome if I could use ndb for that! I.e. if ndb provides a CLI option to specify the debug port ndb connects to.
You can spawn ndb process and add file to os.homedir()/.ndb/ndd_store/<pid>
With following content:
{"targetListUrl":"http://127.0.0.1:<port>/json","argv":process.argv],"cwd":process.cwd()}
ndb will detect this process and automatically attach to it.
I am wondering how does your nice library get websocket url?
Thanks for your answer :) Does this allow debugging multiple processes in parallel? Generally, I don't like to pass launch arguments by writing into global files as this is prone to race conditions and other bugs.
Getting the websocket url is quite easy, the node debugger hosts a rest endoint for that.
Or do you mean how I get the url for the rest endoint? It's just localhost + port. I open the port with process._debug. I've put a sequence diagram in the Readme.
In general I prefer some node flag that will radically simplify node process discovery, I have open pull request for node: https://github.com/nodejs/node/pull/28235 . If it will get merge ndb will run ipc server and you will be able to send detected web socket URL to this server instead of writing to files.
More discussion about node process discovery: https://github.com/nodejs/diagnostics/issues/298
[email protected] runs a little ipc server, external tool can send required information about process to it.
User can get ipc address on Terminal tab in Console drawer (available by Esc), it is listed as NDD_IPC. For expected data format, please take a look on preload.js.
I will think about ways how I can eliminate dependency on NDD_IPC environment variable.