{"source":"doc/api/debugger.md","stability": 2,"stabilityText":"Stable","properties":[{"textRaw":"V8 Inspector Integration for Node.js","name":"js","desc":"<p><strong>NOTE: This is an experimental feature.</strong></p>\n<p>V8 Inspector integration allows attaching Chrome DevTools to Node.js\ninstances for debugging and profiling.</p>\n<p>V8 Inspector can be enabled by passing the <code>--inspect</code> flag when starting a\nNode.js application. It is also possible to supply a custom port with that flag,\ne.g. <code>--inspect=9222</code> will accept DevTools connections on port 9222.</p>\n<p>To break on the first line of the application code, provide the <code>--debug-brk</code>\nflag in addition to <code>--inspect</code>.</p>\n"}],"miscs":[{"textRaw":"Debugger","name":"Debugger","stability": 2,"stabilityText":"Stable","type":"misc","desc":"<p>Node.js includes a full-featured out-of-process debugging utility accessible\nvia a simple [TCP-based protocol][]and built-in debugging client. To use it,\nstart Node.js with the <code>debug</code> argument followed by the path to the script to\ndebug; a prompt will be displayed indicating successful launch of the debugger:</p>\n<pre><code class=\"lang-txt\">$ node debug myscript.js\n&lt; debugger listening on port 5858\nconnecting... ok\nbreak in /home/indutny/Code/git/indutny/myscript.js:1\n  1 x = 5;\n  2 setTimeout(() =&gt;{\n  3   debugger;\ndebug&gt;\n</code></pre>\n<p>Node.js&#39;s debugger client is not a full-featured debugger, but simple step and\ninspection are possible.</p>\n<p>Inserting the statement <code>debugger;</code> into the source code of a script will\nenable a breakpoint at that position in the code:</p>\n<pre><code class=\"lang-js\">// myscript.js\nx = 5;\nsetTimeout(() =&gt;{\n  debugger;\n  console.log(&#39;world&#39;);\n}, 1000);\nconsole.log(&#39;hello&#39;);\n</code></pre>\n<p>Once the debugger is run, a breakpoint will occur at line 4:</p>\n<pre><code class=\"lang-txt\">$ node debug myscript.js\n&lt; debugger listening on port 5858\nconnecting... ok\nbreak in /home/indutny/Code/git/indutny/myscript.js:1\n  1 x = 5;\n  2 setTimeout(() =&gt;{\n  3   debugger;\ndebug&gt; cont\n&lt; hello\nbreak in /home/indutny/Code/git/indutny/myscript.js:3\n  1 x = 5;\n  2 setTimeout(() =&gt;{\n  3   debugger;\n  4   console.log(&#39;world&#39;);\n  5}, 1000);\ndebug&gt; next\nbreak in /home/indutny/Code/git/indutny/myscript.js:4\n  2 setTimeout(() =&gt;{\n  3   debugger;\n  4   console.log(&#39;world&#39;);\n  5}, 1000);\n  6 console.log(&#39;hello&#39;);\ndebug&gt; repl\nPress Ctrl + C to leave debug repl\n&gt; x\n5\n&gt; 2+2\n4\ndebug&gt; next\n&lt; world\nbreak in /home/indutny/Code/git/indutny/myscript.js:5\n  3   debugger;\n  4   console.log(&#39;world&#39;);\n  5}, 1000);\n  6 console.log(&#39;hello&#39;);\n  7\ndebug&gt; quit\n</code></pre>\n<p>The <code>repl</code> command allows code to be evaluated remotely. The <code>next</code> command\nsteps to the next line. Type <code>help</code> to see what other commands are available.</p>\n<p>Pressing <code>enter</code> without typing a command will repeat the previous debugger\ncommand.</p>\n","miscs":[{"textRaw":"Watchers","name":"watchers","desc":"<p>It is possible to watch expression and variable values while debugging. On\nevery breakpoint, each expression from the watchers list will be evaluated\nin the current context and displayed immediately before the breakpoint&#39;s\nsource code listing.</p>\n<p>To begin watching an expression, type <code>watch(&#39;my_expression&#39;)</code>. The command\n<code>watchers</code> will print the active watchers. To remove a watcher, type\n<code>unwatch(&#39;my_expression&#39;)</code>.</p>\n","type":"misc","displayName":"Watchers"},{"textRaw":"Command reference","name":"command_reference","modules":[{"textRaw":"Stepping","name":"Stepping","desc":"<ul>\n<li><code>cont</code>, <code>c</code> - Continue execution</li>\n<li><code>next</code>, <code>n</code> - Step next</li>\n<li><code>step</code>, <code>s</code> - Step in</li>\n<li><code>out</code>, <code>o</code> - Step out</li>\n<li><code>pause</code> - Pause running code (like pause button in Developer Tools)</li>\n</ul>\n","type":"module","displayName":"Breakpoints"},{"textRaw":"Breakpoints","name":"breakpoints","desc":"<ul>\n<li><code>setBreakpoint()</code>, <code>sb()</code> - Set breakpoint on current line</li>\n<li><code>setBreakpoint(line)</code>, <code>sb(line)</code> - Set breakpoint on specific line</li>\n<li><code>setBreakpoint(&#39;fn()&#39;)</code>, <code>sb(...)</code> - Set breakpoint on a first statement in\nfunctions body</li>\n<li><code>setBreakpoint(&#39;script.js&#39;, 1)</code>, <code>sb(...)</code> - Set breakpoint on first line of\nscript.js</li>\n<li><code>clearBreakpoint(&#39;script.js&#39;, 1)</code>, <code>cb(...)</code> - Clear breakpoint in script.js\non line 1</li>\n</ul>\n<p>It is also possible to set a breakpoint in a file (module) that\nisn&#39;t loaded yet:</p>\n<pre><code class=\"lang-txt\">$ ./node debug test/fixtures/break-in-module/main.js\n&lt; debugger listening on port 5858\nconnecting to port 5858... ok\nbreak in test/fixtures/break-in-module/main.js:1\n  1 var mod = require(&#39;./mod.js&#39;);\n  2 mod.hello();\n  3 mod.hello();\ndebug&gt; setBreakpoint(&#39;mod.js&#39;, 23)\nWarning: script &#39;mod.js&#39; was not loaded yet.\n  1 var mod = require(&#39;./mod.js&#39;);\n  2 mod.hello();\n  3 mod.hello();\ndebug&gt; c\nbreak in test/fixtures/break-in-module/mod.js:23\n 21\n 22 exports.hello = () =&gt;{\n 23   return &#39;hello from module&#39;;\n 24};\n 25\ndebug&gt;\n</code></pre>\n","type":"module","displayName":"Breakpoints"},{"textRaw":"Execution control","name":"Execution control","desc":"<ul>\n<li><code>run</code> - Run script (automatically runs on debugger&#39;s start)</li>\n<li><code>restart</code> - Restart script</li>\n<li><code>kill</code> - Kill script</li>\n</ul>\n","type":"module","displayName":"Various"},{"textRaw":"Various","name":"various","desc":"<ul>\n<li><code>scripts</code> - List all loaded scripts</li>\n<li><code>version</code> - Display V8&#39;s version</li>\n</ul>\n","type":"module","displayName":"Various"}],"type":"misc","displayName":"Command reference"},{"textRaw":"Advanced Usage","name":"advanced_usage","desc":"<p>An alternative way of enabling and accessing the debugger is to start\nNode.js with the <code>--debug</code> command-line flag or by signaling an existing\nNode.js process with <code>SIGUSR1</code>.</p>\n<p>Once a process has been set in debug mode this way, it can be inspected\nusing the Node.js debugger by either connecting to the <code>pid</code> of the running\nprocess or via URI reference to the listening debugger:</p>\n<ul>\n<li><code>node debug -p &lt;pid&gt;</code> - Connects to the process via the <code>pid</code></li>\n<li><code>node debug &lt;URI&gt;</code> - Connects to the process via the URI such as\nlocalhost:5858</li>\n</ul>\n","type":"misc","displayName":"Advanced Usage"}],"properties":[{"textRaw":"V8 Inspector Integration for Node.js","name":"js","desc":"<p><strong>NOTE: This is an experimental feature.</strong></p>\n<p>V8 Inspector integration allows attaching Chrome DevTools to Node.js\ninstances for debugging and profiling.</p>\n<p>V8 Inspector can be enabled by passing the <code>--inspect</code> flag when starting a\nNode.js application. It is also possible to supply a custom port with that flag,\ne.g. <code>--inspect=9222</code> will accept DevTools connections on port 9222.</p>\n<p>To break on the first line of the application code, provide the <code>--debug-brk</code>\nflag in addition to <code>--inspect</code>.</p>\n"}]}]}