66
77<!-- type=misc -->
88
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.
1311
1412``` console
1513$ 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
1715< For help, see: https://nodejs.org/en/docs/inspector
16+ <
1817< 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;
2325debug>
2426```
2527
@@ -44,28 +46,33 @@ Once the debugger is run, a breakpoint will occur at line 3:
4446
4547``` console
4648$ 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
4850< For help, see: https://nodejs.org/en/docs/inspector
51+ <
4952< 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;
5460debug> cont
5561< 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+ <
6363break 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');
6976debug> repl
7077Press Ctrl+C to leave debug repl
7178> x
@@ -74,13 +81,15 @@ Press Ctrl+C to leave debug repl
74814
7582debug> next
7683< 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
8391debug> .exit
92+ $
8493```
8594
8695The ` repl ` command allows code to be evaluated remotely. The ` next ` command
@@ -129,11 +138,14 @@ is not loaded yet:
129138
130139``` console
131140$ 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
133142< For help, see: https://nodejs.org/en/docs/inspector
143+ <
134144< Debugger attached.
145+ <
146+ ok
135147Break 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' );
137149 2 mod.hello();
138150 3 mod.hello();
139151debug> setBreakpoint('mod.js', 22)
@@ -239,6 +251,5 @@ Chrome DevTools doesn't support debugging [worker threads][] yet.
239251[ ndb] [ ] can be used to debug them.
240252
241253[ Chrome DevTools Protocol ] : https://chromedevtools.github.io/devtools-protocol/
242- [ V8 Inspector ] : #debugger_v8_inspector_integration_for_node_js
243254[ ndb ] : https://github.com/GoogleChromeLabs/ndb/
244255[ worker threads ] : worker_threads.md
0 commit comments