{ "source": "doc/api/debugger.md", "stability": 2, "stabilityText": "Stable", "properties": [ { "textRaw": "V8 Inspector Integration for Node.js", "name": "js", "desc": "

NOTE: This is an experimental feature.

\n

V8 Inspector integration allows attaching Chrome DevTools to Node.js\ninstances for debugging and profiling.

\n

V8 Inspector can be enabled by passing the --inspect flag when starting a\nNode.js application. It is also possible to supply a custom port with that flag,\ne.g. --inspect=9222 will accept DevTools connections on port 9222.

\n

To break on the first line of the application code, pass the --inspect-brk\nflag instead of --inspect.

\n
$ node --inspect index.js\nDebugger listening on port 9229.\nWarning: This is an experimental feature and could change at any time.\nTo start debugging, open the following URL in Chrome:\n    chrome-devtools://devtools/remote/serve_file/@60cd6e859b9f557d2312f5bf532f6aec5f284980/inspector.html?experiments=true&v8only=true&ws=localhost:9229/node\n
\n" } ], "miscs": [ { "textRaw": "Debugger", "name": "Debugger", "stability": 2, "stabilityText": "Stable", "type": "misc", "desc": "

Node.js includes an out-of-process debugging utility accessible via a\nTCP-based protocol and built-in debugging client. To use it, start Node.js\nwith the debug argument followed by the path to the script to debug; a prompt\nwill be displayed indicating successful launch of the debugger:

\n
$ node debug myscript.js\n< debugger listening on port 5858\nconnecting... ok\nbreak in /home/indutny/Code/git/indutny/myscript.js:1\n  1 x = 5;\n  2 setTimeout(() => {\n  3   debugger;\ndebug>\n
\n

Node.js's debugger client is not a full-featured debugger, but simple step and\ninspection are possible.

\n

Inserting the statement debugger; into the source code of a script will\nenable a breakpoint at that position in the code:

\n
// myscript.js\nx = 5;\nsetTimeout(() => {\n  debugger;\n  console.log('world');\n}, 1000);\nconsole.log('hello');\n
\n

Once the debugger is run, a breakpoint will occur at line 4:

\n
$ node debug myscript.js\n< debugger listening on port 5858\nconnecting... ok\nbreak in /home/indutny/Code/git/indutny/myscript.js:1\n  1 x = 5;\n  2 setTimeout(() => {\n  3   debugger;\ndebug> cont\n< hello\nbreak in /home/indutny/Code/git/indutny/myscript.js:3\n  1 x = 5;\n  2 setTimeout(() => {\n  3   debugger;\n  4   console.log('world');\n  5 }, 1000);\ndebug> next\nbreak in /home/indutny/Code/git/indutny/myscript.js:4\n  2 setTimeout(() => {\n  3   debugger;\n  4   console.log('world');\n  5 }, 1000);\n  6 console.log('hello');\ndebug> repl\nPress Ctrl + C to leave debug repl\n> x\n5\n> 2+2\n4\ndebug> next\n< world\nbreak in /home/indutny/Code/git/indutny/myscript.js:5\n  3   debugger;\n  4   console.log('world');\n  5 }, 1000);\n  6 console.log('hello');\n  7\ndebug> quit\n
\n

The repl command allows code to be evaluated remotely. The next command\nsteps to the next line. Type help to see what other commands are available.

\n

Pressing enter without typing a command will repeat the previous debugger\ncommand.

\n", "miscs": [ { "textRaw": "Watchers", "name": "watchers", "desc": "

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's\nsource code listing.

\n

To begin watching an expression, type watch('my_expression'). The command\nwatchers will print the active watchers. To remove a watcher, type\nunwatch('my_expression').

\n", "type": "misc", "displayName": "Watchers" }, { "textRaw": "Command reference", "name": "command_reference", "modules": [ { "textRaw": "Stepping", "name": "Stepping", "desc": "\n", "type": "module", "displayName": "Breakpoints" }, { "textRaw": "Breakpoints", "name": "breakpoints", "desc": "\n

It is also possible to set a breakpoint in a file (module) that\nis not loaded yet:

\n
$ node debug test/fixtures/break-in-module/main.js\n< 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('./mod.js');\n  2 mod.hello();\n  3 mod.hello();\ndebug> setBreakpoint('mod.js', 23)\nWarning: script 'mod.js' was not loaded yet.\n  1 var mod = require('./mod.js');\n  2 mod.hello();\n  3 mod.hello();\ndebug> c\nbreak in test/fixtures/break-in-module/mod.js:23\n 21\n 22 exports.hello = () => {\n 23   return 'hello from module';\n 24 };\n 25\ndebug>\n
\n", "type": "module", "displayName": "Breakpoints" }, { "textRaw": "Execution control", "name": "Execution control", "desc": "\n", "type": "module", "displayName": "Various" }, { "textRaw": "Various", "name": "various", "desc": "\n", "type": "module", "displayName": "Various" } ], "type": "misc", "displayName": "Command reference" }, { "textRaw": "Advanced Usage", "name": "advanced_usage", "desc": "

An alternative way of enabling and accessing the debugger is to start\nNode.js with the --debug command-line flag or by signaling an existing\nNode.js process with SIGUSR1.

\n

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 pid of the running\nprocess or via URI reference to the listening debugger:

\n\n", "type": "misc", "displayName": "Advanced Usage" } ], "properties": [ { "textRaw": "V8 Inspector Integration for Node.js", "name": "js", "desc": "

NOTE: This is an experimental feature.

\n

V8 Inspector integration allows attaching Chrome DevTools to Node.js\ninstances for debugging and profiling.

\n

V8 Inspector can be enabled by passing the --inspect flag when starting a\nNode.js application. It is also possible to supply a custom port with that flag,\ne.g. --inspect=9222 will accept DevTools connections on port 9222.

\n

To break on the first line of the application code, pass the --inspect-brk\nflag instead of --inspect.

\n
$ node --inspect index.js\nDebugger listening on port 9229.\nWarning: This is an experimental feature and could change at any time.\nTo start debugging, open the following URL in Chrome:\n    chrome-devtools://devtools/remote/serve_file/@60cd6e859b9f557d2312f5bf532f6aec5f284980/inspector.html?experiments=true&v8only=true&ws=localhost:9229/node\n
\n" } ] } ] }