6
6
7
7
Node.js includes an out-of-process debugging utility accessible via a
8
8
[ TCP-based protocol] [ ] and built-in debugging client. To use it, start Node.js
9
- with the ` debug ` argument followed by the path to the script to debug; a prompt
9
+ with the ` inspect ` argument followed by the path to the script to debug; a prompt
10
10
will be displayed indicating successful launch of the debugger:
11
11
12
12
``` txt
13
- $ node debug myscript.js
14
- < Debugger listening on 127.0.0.1:5858
15
- connecting to 127.0.0.1:5858 ... ok
16
- break in /home/indutny/Code/git/indutny/myscript.js:1
17
- > 1 global.x = 5;
13
+ $ node inspect myscript.js
14
+ < Debugger listening on ws://127.0.0.1:9229/80e7a814-7cd3-49fb-921a-2e02228cd5ba
15
+ < For help see https://nodejs.org/en/docs/inspector
16
+ < Debugger attached.
17
+ Break on start in myscript.js:1
18
+ > 1 (function (exports, require, module, __filename, __dirname) { global.x = 5;
18
19
2 setTimeout(() => {
19
- 3 debugger ;
20
+ 3 console.log('world') ;
20
21
debug>
21
22
```
22
23
@@ -40,23 +41,24 @@ console.log('hello');
40
41
Once the debugger is run, a breakpoint will occur at line 3:
41
42
42
43
``` txt
43
- $ node debug myscript.js
44
- < Debugger listening on 127.0.0.1:5858
45
- connecting to 127.0.0.1:5858 ... ok
46
- break in /home/indutny/Code/git/indutny/myscript.js:1
47
- > 1 global.x = 5;
44
+ $ node inspect myscript.js
45
+ < Debugger listening on ws://127.0.0.1:9229/80e7a814-7cd3-49fb-921a-2e02228cd5ba
46
+ < For help see https://nodejs.org/en/docs/inspector
47
+ < Debugger attached.
48
+ Break on start in myscript.js:1
49
+ > 1 (function (exports, require, module, __filename, __dirname) { global.x = 5;
48
50
2 setTimeout(() => {
49
51
3 debugger;
50
52
debug> cont
51
53
< hello
52
- break in /home/indutny/Code/git/indutny/ myscript.js:3
53
- 1 global.x = 5;
54
+ break in myscript.js:3
55
+ 1 (function (exports, require, module, __filename, __dirname) { global.x = 5;
54
56
2 setTimeout(() => {
55
57
> 3 debugger;
56
58
4 console.log('world');
57
59
5 }, 1000);
58
60
debug> next
59
- break in /home/indutny/Code/git/indutny/ myscript.js:4
61
+ break in myscript.js:4
60
62
2 setTimeout(() => {
61
63
3 debugger;
62
64
> 4 console.log('world');
@@ -69,14 +71,14 @@ Press Ctrl + C to leave debug repl
69
71
> 2+2
70
72
4
71
73
debug> next
72
- break in /home/indutny/Code/git/indutny/myscript.js:5
73
74
< world
75
+ break in myscript.js:5
74
76
3 debugger;
75
77
4 console.log('world');
76
78
> 5 }, 1000);
77
79
6 console.log('hello');
78
80
7
79
- debug> quit
81
+ debug> .exit
80
82
```
81
83
82
84
The ` repl ` command allows code to be evaluated remotely. The ` next ` command
@@ -121,27 +123,23 @@ It is also possible to set a breakpoint in a file (module) that
121
123
is not loaded yet:
122
124
123
125
``` txt
124
- $ node debug test/fixtures/break-in-module/main.js
125
- < Debugger listening on 127.0.0.1:5858
126
- connecting to 127.0.0.1:5858 ... ok
127
- break in test/fixtures/break-in-module/main.js:1
128
- > 1 const mod = require('./mod.js');
126
+ $ node inspect test/fixtures/break-in-module/main.js
127
+ < Debugger listening on ws://127.0.0.1:9229/4e3db158-9791-4274-8909-914f7facf3bd
128
+ < For help see https://nodejs.org/en/docs/inspector
129
+ < Debugger attached.
130
+ Break on start in test/fixtures/break-in-module/main.js:1
131
+ > 1 (function (exports, require, module, __filename, __dirname) { const mod = require('./mod.js');
129
132
2 mod.hello();
130
133
3 mod.hello();
131
- debug> setBreakpoint('mod.js', 2 )
134
+ debug> setBreakpoint('mod.js', 22 )
132
135
Warning: script 'mod.js' was not loaded yet.
133
- > 1 const mod = require('./mod.js');
134
- 2 mod.hello();
135
- 3 mod.hello();
136
- 4 debugger;
137
- 5
138
- 6 });
139
136
debug> c
140
- break in test/fixtures/break-in-module/mod.js:2
141
- 1 exports.hello = function() {
142
- > 2 return 'hello from module';
143
- 3 };
144
- 4
137
+ break in test/fixtures/break-in-module/mod.js:22
138
+ 20 // USE OR OTHER DEALINGS IN THE SOFTWARE.
139
+ 21
140
+ >22 exports.hello = function() {
141
+ 23 return 'hello from module';
142
+ 24 };
145
143
debug>
146
144
```
147
145
0 commit comments