6
6
7
7
<!-- type=misc -->
8
8
9
- Node.js includes an out-of-process debugging utility accessible via a
10
- [ V8 Inspector] [ ] and built-in debugging client. To use it, start Node.js
11
- with the ` inspect ` argument followed by the path to the script to debug; a
12
- prompt will be displayed indicating successful launch of the debugger:
9
+ Node.js includes a command-line debugging utility. To use it, start Node.js
10
+ with the ` inspect ` argument followed by the path to the script to debug.
13
11
14
12
``` console
15
13
$ node inspect myscript.js
16
- < Debugger listening on ws://127.0.0.1:9229/80e7a814-7cd3-49fb-921a-2e02228cd5ba
14
+ < Debugger listening on ws://127.0.0.1:9229/621111f9-ffcb-4e82-b718-48a145fa5db8
17
15
< For help, see: https://nodejs.org/en/docs/inspector
16
+ <
18
17
< Debugger attached.
19
- Break on start in myscript.js:1
20
- > 1 (function (exports, require, module, __filename, __dirname) { global.x = 5;
21
- 2 setTimeout(() => {
22
- 3 console.log('world');
18
+ <
19
+ ok
20
+ Break on start in myscript.js:2
21
+ 1 // myscript.js
22
+ > 2 global.x = 5;
23
+ 3 setTimeout(() => {
24
+ 4 debugger;
23
25
debug>
24
26
```
25
27
@@ -44,28 +46,33 @@ Once the debugger is run, a breakpoint will occur at line 3:
44
46
45
47
``` console
46
48
$ node inspect myscript.js
47
- < Debugger listening on ws://127.0.0.1:9229/80e7a814-7cd3-49fb-921a-2e02228cd5ba
49
+ < Debugger listening on ws://127.0.0.1:9229/621111f9-ffcb-4e82-b718-48a145fa5db8
48
50
< For help, see: https://nodejs.org/en/docs/inspector
51
+ <
49
52
< Debugger attached.
50
- Break on start in myscript.js:1
51
- > 1 (function (exports, require, module, __filename, __dirname) { global.x = 5;
52
- 2 setTimeout(() => {
53
- 3 debugger;
53
+ <
54
+ ok
55
+ Break on start in myscript.js:2
56
+ 1 // myscript.js
57
+ > 2 global.x = 5;
58
+ 3 setTimeout(() => {
59
+ 4 debugger;
54
60
debug> cont
55
61
< hello
56
- break in myscript.js:3
57
- 1 (function (exports, require, module, __filename, __dirname) { global.x = 5;
58
- 2 setTimeout(() => {
59
- > 3 debugger;
60
- 4 console.log('world');
61
- 5 }, 1000);
62
- debug> next
62
+ <
63
63
break in myscript.js:4
64
- 2 setTimeout(() => {
65
- 3 debugger;
66
- > 4 console.log(' world' );
67
- 5 }, 1000);
68
- 6 console.log('hello');
64
+ 2 global.x = 5;
65
+ 3 setTimeout(() => {
66
+ > 4 debugger;
67
+ 5 console.log('world');
68
+ 6 }, 1000);
69
+ debug> next
70
+ break in myscript.js:5
71
+ 3 setTimeout(() => {
72
+ 4 debugger;
73
+ > 5 console.log(' world' );
74
+ 6 }, 1000);
75
+ 7 console.log('hello');
69
76
debug> repl
70
77
Press Ctrl+C to leave debug repl
71
78
> x
@@ -74,13 +81,15 @@ Press Ctrl+C to leave debug repl
74
81
4
75
82
debug> next
76
83
< world
77
- break in myscript.js:5
78
- 3 debugger;
79
- 4 console.log('world');
80
- > 5 }, 1000);
81
- 6 console.log('hello');
82
- 7
84
+ <
85
+ break in myscript.js:6
86
+ 4 debugger;
87
+ 5 console.log('world');
88
+ > 6 }, 1000);
89
+ 7 console.log('hello');
90
+ 8
83
91
debug> .exit
92
+ $
84
93
```
85
94
86
95
The ` repl ` command allows code to be evaluated remotely. The ` next ` command
@@ -129,11 +138,14 @@ is not loaded yet:
129
138
130
139
``` console
131
140
$ node inspect main.js
132
- < Debugger listening on ws://127.0.0.1:9229/4e3db158-9791-4274-8909-914f7facf3bd
141
+ < Debugger listening on ws://127.0.0.1:9229/48a5b28a-550c-471b-b5e1-d13dd7165df9
133
142
< For help, see: https://nodejs.org/en/docs/inspector
143
+ <
134
144
< Debugger attached.
145
+ <
146
+ ok
135
147
Break on start in main.js:1
136
- > 1 (function (exports, require, module, __filename, __dirname) { const mod = require(' ./mod.js' );
148
+ > 1 const mod = require(' ./mod.js' );
137
149
2 mod.hello();
138
150
3 mod.hello();
139
151
debug> setBreakpoint('mod.js', 22)
@@ -239,6 +251,5 @@ Chrome DevTools doesn't support debugging [worker threads][] yet.
239
251
[ ndb] [ ] can be used to debug them.
240
252
241
253
[ Chrome DevTools Protocol ] : https://chromedevtools.github.io/devtools-protocol/
242
- [ V8 Inspector ] : #debugger_v8_inspector_integration_for_node_js
243
254
[ ndb ] : https://github.com/GoogleChromeLabs/ndb/
244
255
[ worker threads ] : worker_threads.md
0 commit comments