Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

CLI option to attach debugger to a port #249

Open
hediet opened this issue Mar 22, 2019 · 4 comments
Open

CLI option to attach debugger to a port #249

hediet opened this issue Mar 22, 2019 · 4 comments
Labels

Comments

@hediet
Copy link

hediet commented Mar 22, 2019

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.

@alexkozy
Copy link
Contributor

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?

@hediet
Copy link
Author

hediet commented Mar 24, 2019

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.

@alexkozy
Copy link
Contributor

In general I prefer some node flag that will radically simplify node process discovery, I have open pull request for node: nodejs/node#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: nodejs/diagnostics#298

@alexkozy
Copy link
Contributor

alexkozy commented Jul 8, 2019

ndb@1.1.0 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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants