Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: update debugger.md #13777

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 35 additions & 32 deletions doc/api/debugger.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ will be displayed indicating successful launch of the debugger:

```txt
$ node debug myscript.js
< Debugger listening on 127.0.0.1:5858
connecting to 127.0.0.1:5858 ... ok
break in /home/indutny/Code/git/indutny/myscript.js:1
> 1 global.x = 5;
(node:8468) [DEP0068] DeprecationWarning: `node debug` is deprecated.
Please use `node inspect` instead.
< Debugger listening on ws://127.0.0.1:9229/ebf2d19a-5300-4b1f-a60d-1ed8326a9049
< For help see https://nodejs.org/en/docs/inspector
Break on start in /home/indutny/Code/git/indutny/myscript.js:1
> 1 (function (exports, require, module, __filename, __dirname) { global.x = 5;
2 setTimeout(() => {
3 debugger;
debug>
```

(In the example above, the UUID ebf2d19a-5300-4b1f-a60d-1ed8326a9049
at the end of the URL is generated on the fly, it varies in different
debugging sessions.)

Node.js's debugger client is not a full-featured debugger, but simple step and
inspection are possible.

Expand All @@ -40,17 +46,18 @@ console.log('hello');
Once the debugger is run, a breakpoint will occur at line 3:

```txt
$ node debug myscript.js
< Debugger listening on 127.0.0.1:5858
connecting to 127.0.0.1:5858 ... ok
break in /home/indutny/Code/git/indutny/myscript.js:1
> 1 global.x = 5;
(node:8468) [DEP0068] DeprecationWarning: `node debug` is deprecated.
Please use `node inspect` instead.
< Debugger listening on ws://127.0.0.1:9229/ebf2d19a-5300-4b1f-a60d-1ed8326a9049
< For help see https://nodejs.org/en/docs/inspector
Break on start in /home/indutny/Code/git/indutny/myscript.js:1
> 1 (function (exports, require, module, __filename, __dirname) { global.x = 5;
2 setTimeout(() => {
3 debugger;
debug> cont
< hello
break in /home/indutny/Code/git/indutny/myscript.js:3
1 global.x = 5;
1 (function (exports, require, module, __filename, __dirname) { global.x = 5;
2 setTimeout(() => {
> 3 debugger;
4 console.log('world');
Expand All @@ -69,14 +76,14 @@ Press Ctrl + C to leave debug repl
> 2+2
4
debug> next
break in /home/indutny/Code/git/indutny/myscript.js:5
< world
break in /home/indutny/Code/git/indutny/myscript.js:5
3 debugger;
4 console.log('world');
> 5 }, 1000);
6 console.log('hello');
7
debug> quit
debug> .exit
```

The `repl` command allows code to be evaluated remotely. The `next` command
Expand Down Expand Up @@ -122,26 +129,23 @@ is not loaded yet:

```txt
$ node debug test/fixtures/break-in-module/main.js
< Debugger listening on 127.0.0.1:5858
connecting to 127.0.0.1:5858 ... ok
(node:8564) [DEP0068] DeprecationWarning: `node debug` is deprecated.
Please use `node inspect` instead.
< Debugger listening on ws://127.0.0.1:9229/773f22ce-49a7-450f-85be-81bfb92e02d3
< For help see https://nodejs.org/en/docs/inspector
break in test/fixtures/break-in-module/main.js:1
> 1 const mod = require('./mod.js');
> 1 (function (exports, require, module, __filename, __dirname) { const mod = require('./mod.js');
2 mod.hello();
3 mod.hello();
debug> setBreakpoint('mod.js', 2)
debug> setBreakpoint('mod.js', 23)
Warning: script 'mod.js' was not loaded yet.
> 1 const mod = require('./mod.js');
2 mod.hello();
3 mod.hello();
4 debugger;
5
6 });
debug> c
break in test/fixtures/break-in-module/mod.js:2
1 exports.hello = function() {
> 2 return 'hello from module';
3 };
4
break in test/fixtures/break-in-module/mod.js:23
21
22 exports.hello = function() {
>23 return 'hello from module';
24 };
25
debug>
```

Expand Down Expand Up @@ -184,14 +188,13 @@ flag instead of `--inspect`.

```txt
$ node --inspect index.js
Debugger listening on 127.0.0.1:9229.
To start debugging, open the following URL in Chrome:
chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:9229/dc9010dd-f8b8-4ac5-a510-c1a114ec7d29
Debugger listening on ws://127.0.0.1:9229/10b81040-7534-4c13-8aba-78e9f50d70f8
For help see https://nodejs.org/en/docs/inspector
```

(In the example above, the UUID dc9010dd-f8b8-4ac5-a510-c1a114ec7d29
(In the example above, the UUID 10b81040-7534-4c13-8aba-78e9f50d70f8
at the end of the URL is generated on the fly, it varies in different
debugging sessions.)

[Chrome Debugging Protocol]: https://chromedevtools.github.io/debugger-protocol-viewer/
[Chrome Debugging Protocol]: https://chromedevtools.github.io/devtools-protocol/
[TCP-based protocol]: #debugger_tcp_based_protocol