66
77<!-- type=misc -->
88
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.
9+ Node.js includes a command-line debugging utility. The Node.js debugger client
10+ is not a full-featured debugger, but simple stepping and inspection are
11+ possible.
12+
13+ To use it, start Node.js with the ` inspect ` argument followed by the path to the
14+ script to debug.
1115
1216``` console
1317$ node inspect myscript.js
@@ -25,40 +29,26 @@ Break on start in myscript.js:2
2529debug>
2630```
2731
28- The Node.js debugger client is not a full-featured debugger, but simple step and
29- inspection are possible.
30-
31- Inserting the statement ` debugger; ` into the source code of a script will
32- enable a breakpoint at that position in the code:
33-
34- <!-- eslint-disable no-debugger -->
32+ The debugger automatically breaks on the first executable line. To instead
33+ run until the first breakpoint (specified by a [ ` debugger ` ] [ ] statement), set
34+ the ` NODE_INSPECT_RESUME_ON_START ` environment variable to ` 1 ` .
3535
36- ``` js
36+ ``` console
37+ $ cat myscript.js
3738// myscript.js
3839global.x = 5;
3940setTimeout(() => {
4041 debugger;
4142 console.log('world');
4243}, 1000);
4344console.log('hello');
44- ```
45-
46- Once the debugger is run, a breakpoint will occur at line 3:
47-
48- ``` console
49- $ node inspect myscript.js
50- < Debugger listening on ws://127.0.0.1:9229/621111f9-ffcb-4e82-b718-48a145fa5db8
45+ $ NODE_INSPECT_RESUME_ON_START=1 node inspect myscript.js
46+ < Debugger listening on ws://127.0.0.1:9229/f1ed133e-7876-495b-83ae-c32c6fc319c2
5147< For help, see: https://nodejs.org/en/docs/inspector
5248<
49+ connecting to 127.0.0.1:9229 ... ok
5350< Debugger attached.
5451<
55- ok
56- Break on start in myscript.js:2
57- 1 // myscript.js
58- > 2 global.x = 5;
59- 3 setTimeout(() => {
60- 4 debugger;
61- debug> cont
6252< hello
6353<
6454break in myscript.js:4
@@ -252,5 +242,6 @@ Chrome DevTools doesn't support debugging [worker threads][] yet.
252242[ ndb] [ ] can be used to debug them.
253243
254244[ Chrome DevTools Protocol ] : https://chromedevtools.github.io/devtools-protocol/
245+ [ `debugger` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger
255246[ ndb ] : https://github.com/GoogleChromeLabs/ndb/
256247[ worker threads ] : worker_threads.md
0 commit comments