How to debug nodejs process with browser debugger?
Shows the process of starting a node process in debug (inspect) mode, attaching a debugger, and using the debugger tools - step next, add breakpoint, remove breakpoint, and log out variables from the scope. In that demo we : - ```sh node --inspect-brk ../node_modules/jasmine/bin/jasmine.js ``` Start the Jasmine script in debug mode (aka inspect mode) and outputs the WebSocket address, port, and id : `Debugger listening on ws://127.0.0.1:9229/11bc3c5b-4703-4a09-926d-6f03d5c4ef00`. `--inspect-brk` means that the debugger server will break on the first line of the script and wait for a debugger client (in this case the browser) to attach. _In the example the node_modules are one folder up - `../node_modules`. Usually, it's `./node_modules` like in the example below._ - Then, we show the browser and navigate to `edge://inspect` (for chrome it would be `chrome://inspect`). - In the inspect tab we select the node process which is automatically shown based on the default config - localhost and port 9229. The `Configuration` button allows for adding other addresses or ports to search (although it seems using another port e.g. 9876 does not work). - After the browser (debug client) attaches we see the first line of the script - Jasmine. - Clicking on the `Resume` button we continue to a `debugger` statement in our code. - At this point we are debugging our script. We can add breakpoints, remove breakpoints, evaluate expressions in the console that run in the context of the current scope i.e. wherever the script breaks and whatever it sees we can use in the evaluation. There's a bunch of stuff that the debugger allows - [Edge](https://docs.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/) [Chrome](https://developer.chrome.com/docs/devtools/javascript/). - After we finish debugging and allow the script to run its course and end the debugger server waits for the debugger client to disconnect `Waiting for the debugger to disconnect...` and then closes the WebSocket and exits.
Shows the process of starting a node process in debug (inspect) mode, attaching a debugger, and using the debugger tools - step next, add breakpoint, remove breakpoint, and log out variables from the scope. In that demo we : - ```sh node --inspect-brk ../node_modules/jasmine/bin/jasmine.js ``` Start the Jasmine script in debug mode (aka inspect mode) and outputs the WebSocket address, port, and id : `Debugger listening on ws://127.0.0.1:9229/11bc3c5b-4703-4a09-926d-6f03d5c4ef00`. `--inspect-brk` means that the debugger server will break on the first line of the script and wait for a debugger client (in this case the browser) to attach. _In the example the node_modules are one folder up - `../node_modules`. Usually, it's `./node_modules` like in the example below._ - Then, we show the browser and navigate to `edge://inspect` (for chrome it would be `chrome://inspect`). - In the inspect tab we select the node process which is automatically shown based on the default config - localhost and port 9229. The `Configuration` button allows for adding other addresses or ports to search (although it seems using another port e.g. 9876 does not work). - After the browser (debug client) attaches we see the first line of the script - Jasmine. - Clicking on the `Resume` button we continue to a `debugger` statement in our code. - At this point we are debugging our script. We can add breakpoints, remove breakpoints, evaluate expressions in the console that run in the context of the current scope i.e. wherever the script breaks and whatever it sees we can use in the evaluation. There's a bunch of stuff that the debugger allows - [Edge](https://docs.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/) [Chrome](https://developer.chrome.com/docs/devtools/javascript/). - After we finish debugging and allow the script to run its course and end the debugger server waits for the debugger client to disconnect `Waiting for the debugger to disconnect...` and then closes the WebSocket and exits.