{
  "type": "module",
  "source": "doc/api/debugger.md",
  "introduced_in": "v0.9.12",
  "stability": 2,
  "stabilityText": "Stable",
  "miscs": [
    {
      "textRaw": "Debugger",
      "name": "Debugger",
      "introduced_in": "v0.9.12",
      "type": "misc",
      "stability": 2,
      "stabilityText": "Stable",
      "desc": "<p>Node.js includes a command-line debugging utility. The Node.js debugger client\nis not a full-featured debugger, but simple stepping and inspection are\npossible.</p>\n<p>The debugger supports two modes of operation: <a href=\"#interactive-mode\">interactive mode</a> and <a href=\"#probe-mode\">non-interactive probe mode</a>.</p>",
      "miscs": [
        {
          "textRaw": "Interactive mode",
          "name": "interactive_mode",
          "type": "misc",
          "desc": "<pre><code class=\"language-console\">$ node inspect [--port=&#x3C;port>] [&#x3C;node-option> ...] [&#x3C;script> [&#x3C;script-args>] | &#x3C;host>:&#x3C;port> | -p &#x3C;pid>]\n</code></pre>\n<p>To use it, start Node.js with the <code>inspect</code> argument followed by the path to the\nscript to debug.</p>\n<pre><code class=\"language-console\">$ node inspect myscript.js\n&#x3C; Debugger listening on ws://127.0.0.1:9229/621111f9-ffcb-4e82-b718-48a145fa5db8\n&#x3C; For help, see: https://nodejs.org/learn/getting-started/debugging\n&#x3C;\nconnecting to 127.0.0.1:9229 ... ok\n&#x3C; Debugger attached.\n&#x3C;\n ok\nBreak on start in myscript.js:2\n  1 // myscript.js\n> 2 global.x = 5;\n  3 setTimeout(() => {\n  4   debugger;\ndebug>\n</code></pre>\n<p>The debugger automatically breaks on the first executable line. To instead\nrun until the first breakpoint (specified by a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger\"><code>debugger</code></a> statement), set\nthe <code>NODE_INSPECT_RESUME_ON_START</code> environment variable to <code>1</code>.</p>\n<pre><code class=\"language-console\">$ cat myscript.js\n// myscript.js\nglobal.x = 5;\nsetTimeout(() => {\n  debugger;\n  console.log('world');\n}, 1000);\nconsole.log('hello');\n$ NODE_INSPECT_RESUME_ON_START=1 node inspect myscript.js\n&#x3C; Debugger listening on ws://127.0.0.1:9229/f1ed133e-7876-495b-83ae-c32c6fc319c2\n&#x3C; For help, see: https://nodejs.org/learn/getting-started/debugging\n&#x3C;\nconnecting to 127.0.0.1:9229 ... ok\n&#x3C; Debugger attached.\n&#x3C;\n&#x3C; hello\n&#x3C;\nbreak in myscript.js:4\n  2 global.x = 5;\n  3 setTimeout(() => {\n> 4   debugger;\n  5   console.log('world');\n  6 }, 1000);\ndebug> next\nbreak in myscript.js:5\n  3 setTimeout(() => {\n  4   debugger;\n> 5   console.log('world');\n  6 }, 1000);\n  7 console.log('hello');\ndebug> repl\nPress Ctrl+C to leave debug repl\n> x\n5\n> 2 + 2\n4\ndebug> next\n&#x3C; world\n&#x3C;\nbreak in myscript.js:6\n  4   debugger;\n  5   console.log('world');\n> 6 }, 1000);\n  7 console.log('hello');\n  8\ndebug> .exit\n$\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>",
          "modules": [
            {
              "textRaw": "Watchers",
              "name": "watchers",
              "type": "module",
              "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's\nsource code listing.</p>\n<p>To begin watching an expression, type <code>watch('my_expression')</code>. The command\n<code>watchers</code> will print the active watchers. To remove a watcher, type\n<code>unwatch('my_expression')</code>.</p>",
              "displayName": "Watchers"
            }
          ],
          "displayName": "Interactive mode"
        },
        {
          "textRaw": "Command reference",
          "name": "command_reference",
          "type": "misc",
          "modules": [
            {
              "textRaw": "Stepping",
              "name": "stepping",
              "type": "module",
              "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>",
              "modules": [
                {
                  "textRaw": "Breakpoints",
                  "name": "breakpoints",
                  "type": "module",
                  "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('fn()')</code>, <code>sb(...)</code>: Set breakpoint on a first statement in\nfunction's body</li>\n<li><code>setBreakpoint('script.js', 1)</code>, <code>sb(...)</code>: Set breakpoint on first line of\n<code>script.js</code></li>\n<li><code>setBreakpoint('script.js', 1, 'num &#x3C; 4')</code>, <code>sb(...)</code>: Set conditional\nbreakpoint on first line of <code>script.js</code> that only breaks when <code>num &#x3C; 4</code>\nevaluates to <code>true</code></li>\n<li><code>clearBreakpoint('script.js', 1)</code>, <code>cb(...)</code>: Clear breakpoint in <code>script.js</code>\non line 1</li>\n</ul>\n<p>It is also possible to set a breakpoint in a file (module) that\nis not loaded yet:</p>\n<pre><code class=\"language-console\">$ node inspect main.js\n&#x3C; Debugger listening on ws://127.0.0.1:9229/48a5b28a-550c-471b-b5e1-d13dd7165df9\n&#x3C; For help, see: https://nodejs.org/learn/getting-started/debugging\n&#x3C;\nconnecting to 127.0.0.1:9229 ... ok\n&#x3C; Debugger attached.\n&#x3C;\nBreak on start in main.js:1\n> 1 const mod = require('./mod.js');\n  2 mod.hello();\n  3 mod.hello();\ndebug> setBreakpoint('mod.js', 22)\nWarning: script 'mod.js' was not loaded yet.\ndebug> c\nbreak in mod.js:22\n 20 // USE OR OTHER DEALINGS IN THE SOFTWARE.\n 21\n>22 exports.hello = function() {\n 23   return 'hello from module';\n 24 };\ndebug>\n</code></pre>\n<p>It is also possible to set a conditional breakpoint that only breaks when a\ngiven expression evaluates to <code>true</code>:</p>\n<pre><code class=\"language-console\">$ node inspect main.js\n&#x3C; Debugger listening on ws://127.0.0.1:9229/ce24daa8-3816-44d4-b8ab-8273c8a66d35\n&#x3C; For help, see: https://nodejs.org/learn/getting-started/debugging\n&#x3C;\nconnecting to 127.0.0.1:9229 ... ok\n&#x3C; Debugger attached.\nBreak on start in main.js:7\n  5 }\n  6\n> 7 addOne(10);\n  8 addOne(-1);\n  9\ndebug> setBreakpoint('main.js', 4, 'num &#x3C; 0')\n  1 'use strict';\n  2\n  3 function addOne(num) {\n> 4   return num + 1;\n  5 }\n  6\n  7 addOne(10);\n  8 addOne(-1);\n  9\ndebug> cont\nbreak in main.js:4\n  2\n  3 function addOne(num) {\n> 4   return num + 1;\n  5 }\n  6\ndebug> exec('num')\n-1\ndebug>\n</code></pre>",
                  "displayName": "Breakpoints"
                },
                {
                  "textRaw": "Information",
                  "name": "information",
                  "type": "module",
                  "desc": "<ul>\n<li><code>backtrace</code>, <code>bt</code>: Print backtrace of current execution frame</li>\n<li><code>list(5)</code>: List scripts source code with 5 line context (5 lines before and\nafter)</li>\n<li><code>watch(expr)</code>: Add expression to watch list</li>\n<li><code>unwatch(expr)</code>: Remove expression from watch list</li>\n<li><code>unwatch(index)</code>: Remove expression at specific index from watch list</li>\n<li><code>watchers</code>: List all watchers and their values (automatically listed on each\nbreakpoint)</li>\n<li><code>repl</code>: Open debugger's repl for evaluation in debugging script's context</li>\n<li><code>exec expr</code>, <code>p expr</code>: Execute an expression in debugging script's context and\nprint its value</li>\n<li><code>profile</code>: Start CPU profiling session</li>\n<li><code>profileEnd</code>: Stop current CPU profiling session</li>\n<li><code>profiles</code>: List all completed CPU profiling sessions</li>\n<li><code>profiles[n].save(filepath = 'node.cpuprofile')</code>: Save CPU profiling session\nto disk as JSON</li>\n<li><code>takeHeapSnapshot(filepath = 'node.heapsnapshot')</code>: Take a heap snapshot\nand save to disk as JSON</li>\n</ul>",
                  "displayName": "Information"
                },
                {
                  "textRaw": "Execution control",
                  "name": "execution_control",
                  "type": "module",
                  "desc": "<ul>\n<li><code>run</code>: Run script (automatically runs on debugger's start)</li>\n<li><code>restart</code>: Restart script</li>\n<li><code>kill</code>: Kill script</li>\n</ul>",
                  "displayName": "Execution control"
                },
                {
                  "textRaw": "Various",
                  "name": "various",
                  "type": "module",
                  "desc": "<ul>\n<li><code>scripts</code>: List all loaded scripts</li>\n<li><code>version</code>: Display V8's version</li>\n</ul>",
                  "displayName": "Various"
                }
              ],
              "displayName": "Stepping"
            }
          ],
          "displayName": "Command reference"
        },
        {
          "textRaw": "Probe mode",
          "name": "probe_mode",
          "type": "misc",
          "meta": {
            "added": [
              "v26.1.0"
            ],
            "changes": [
              {
                "version": "v26.3.0",
                "pr-url": "https://github.com/nodejs/node/pull/63437",
                "description": "Add `probe_failure` terminal `error` event for inspector-side mid-session failures, and `error.details` for additional context on per-hit and terminal errors."
              },
              {
                "version": "v26.2.0",
                "pr-url": "https://github.com/nodejs/node/pull/63286",
                "description": "JSON report schema bumped to v2. Probe `target` is now `{ suffix, line, column? }` instead of an array. Each \"hit\" event carries a `location` field reporting the actual evaluation location.  When the probe does not specify a column, it binds to the first executable column instead of defaulting to 1."
              }
            ]
          },
          "stability": 1,
          "stabilityText": "Experimental",
          "desc": "<p><code>node inspect</code> supports a non-interactive probe mode for inspecting runtime values\nin an application via the flag <code>--probe</code>.</p>\n<p>Currently, probe mode only supports launching a new process from the entry point\nscript specified on the command line.</p>\n<p>The probe mode sets one or more source breakpoints, evaluates specified\nexpressions whenever the execution reaches a breakpoint, and prints one\nfinal report of all the evaluated expressions when the session ends\n(either on normal completion, error, or timeout). This allows developers to perform\nprintf-style debugging without having to modify the application code and\nclean up afterwards. It also supports structured JSON output for tool use.</p>\n<pre><code class=\"language-console\">$ node inspect --probe &#x3C;file>:&#x3C;line>[:&#x3C;col>] --expr &#x3C;expr>\n              [--probe &#x3C;file>:&#x3C;line>[:&#x3C;col>] --expr &#x3C;expr> ...]\n              [--json] [--preview] [--timeout=&#x3C;ms>] [--port=&#x3C;port>]\n              [--] [&#x3C;node-option> ...] &#x3C;script> [&#x3C;script-args> ...]\n</code></pre>\n<ul>\n<li><code>--probe &#x3C;file>:&#x3C;line>[:&#x3C;col>]</code>: Source location of the probe. When execution\nreaches the location, the provided expressions are evaluated and printed in\nthe output. <code>&#x3C;file></code> matches the URL suffix of the script to probe.\n<code>&#x3C;line></code> and <code>&#x3C;col></code> numbers are 1-based. When <code>&#x3C;col></code> is omitted, the probe\nbinds to the first executable column on the line.</li>\n<li><code>--expr &#x3C;expr></code>: JavaScript expression to evaluate whenever execution reaches\nthe location specified by the preceding <code>--probe</code>.\nMust immediately follow the <code>--probe</code> it belongs to.</li>\n<li><code>--timeout=&#x3C;ms></code>: A global wall-clock deadline for the entire probe session.\nThe default is <code>30000</code>. This can be used to probe a long-running application\nthat can be terminated externally.</li>\n<li><code>--json</code>: If used, prints a structured JSON report instead of the default text report.</li>\n<li><code>--preview</code>: If used, non-primitive values will include CDP property previews for\nobject-like JSON probe values.</li>\n<li><code>--port=&#x3C;port></code>: Selects the local inspector port where the probing session\nwill listen. Defaults to <code>0</code>, which requests a random port.</li>\n<li><code>--</code> is optional unless the child needs its own Node.js flags.</li>\n</ul>\n<p>Additional rules about the <code>--probe</code> and <code>--expr</code> arguments:</p>\n<ul>\n<li><code>--probe &#x3C;file>:&#x3C;line>[:&#x3C;col>]</code> and <code>--expr &#x3C;expr></code> are strict pairs. Each\n<code>--probe</code> must be followed immediately by exactly one <code>--expr</code>.</li>\n<li><code>--timeout</code>, <code>--json</code>, <code>--preview</code>, and <code>--port</code> are global probe options\nfor the whole probe session. They may appear before or between probe pairs,\nbut not between a <code>--probe</code> and its matching <code>--expr</code>.</li>\n<li>If additional Node.js execution arguments need to be passed to the child\nscript, <code>--</code> must be used to separate the probe options from the Node.js\noptions for the child script.</li>\n</ul>\n<p>Example:</p>\n<pre><code class=\"language-console\">$ node inspect --probe app.js:10 --expr \"user\"\n               --probe src/utils.js:5:15 --expr \"config.options\"\n               --json --preview -- --no-warnings app.js --arg-for-app=foo\n</code></pre>",
          "modules": [
            {
              "textRaw": "Probe output format",
              "name": "probe_output_format",
              "type": "module",
              "desc": "<p>When the probe session ends, the probing process prints a final report of all the probe hits and results.</p>\n<p>Consider this script:</p>\n<pre><code class=\"language-js\">// cli.js\nlet maxRSS = 0;\nfor (let i = 0; i &#x3C; 2; i++) {\n  const { rss } = process.memoryUsage();\n  maxRSS = Math.max(maxRSS, rss);\n}\n</code></pre>\n<p>Without <code>--json</code>, by default the output is printed in a human-readable text format:</p>\n<pre><code class=\"language-console\">$ node inspect --probe cli.js:5 --expr 'rss' cli.js\nHit 1 at file:///path/to/cli.js:5:3\n  rss = 54935552\nHit 2 at file:///path/to/cli.js:5:3\n  rss = 55083008\nCompleted\n</code></pre>\n<p>The original <code>&#x3C;file>:&#x3C;line>[:&#x3C;col>]</code> passed to <code>--probe</code> may be resolved to a different\nlocation to ensure it's pausable, or it can match multiple loaded scripts, so the actual\nevaluation location helps disambiguate the results.</p>\n<p>Primitive results are printed directly, while objects and arrays use Chrome\nDevTools Protocol preview data when available. Other non-primitive values\nfall back to the Chrome DevTools Protocol <code>description</code> string.\nExpression failures are recorded as <code>[error] ...</code> lines and do not fail\nthe overall session. If richer text formatting is needed, wrap the expression\nin <code>JSON.stringify(...)</code> or <code>util.inspect(...)</code>.</p>\n<p>When <code>--json</code> is used, the output shape looks like this:</p>\n<pre><code class=\"language-console\">$ node inspect --json --probe cli.js:5 --expr 'rss' cli.js\n{\"v\":2,\"probes\":[{\"expr\":\"rss\",\"target\":{\"suffix\":\"cli.js\",\"line\":5}}],\"results\":[{\"probe\":0,\"event\":\"hit\",\"hit\":1,\"location\":{\"url\":\"file:///path/to/cli.js\",\"line\":5,\"column\":3},\"result\":{\"type\":\"number\",\"value\":55443456,\"description\":\"55443456\"}},{\"probe\":0,\"event\":\"hit\",\"hit\":2,\"location\":{\"url\":\"file:///path/to/cli.js\",\"line\":5,\"column\":3},\"result\":{\"type\":\"number\",\"value\":55574528,\"description\":\"55574528\"}},{\"event\":\"completed\"}]}\n</code></pre>\n<pre><code class=\"language-json\">{\n  \"v\": 2, // Probe JSON schema version.\n  \"probes\": [\n    {\n      \"expr\": \"rss\", // The expression paired with --probe.\n      \"target\": {\n        // The user's probe specification. `suffix` is the raw &#x3C;file> passed\n        // to --probe and is matched as a path-separator-anchored suffix\n        // against every loaded script's URL. `column` is present only if the\n        // user supplied `:col`. The actual evaluation location may differ\n        // from the target and will be reported in each hit's `location` field.\n        \"suffix\": \"cli.js\",\n        \"line\": 5\n      }\n    }\n  ],\n  \"results\": [\n    {\n      \"probe\": 0, // Index into probes[].\n      \"event\": \"hit\", // Hit events are recorded in observation order.\n      \"hit\": 1, // 1-based hit count for this probe.\n      \"location\": {\n        // The actual location where the execution is paused to evaluate\n        // the expression of the probe. This may differ from the probe's\n        // target due to pausability adjustments or multiple matches.\n        \"url\": \"file:///path/to/cli.js\",\n        \"line\": 5,\n        \"column\": 3\n      },\n      \"result\": {\n        \"type\": \"number\",\n        \"value\": 55443456,\n        \"description\": \"55443456\"\n      }\n      // If the probe expression throws, fails, or never completes, the entry\n      // carries an `error` field instead of `result` with the shape\n      // `{ message: string, details?: object }`. The `message` and `details`\n      // content is informational only and may change between releases.\n    },\n    {\n      \"probe\": 0,\n      \"event\": \"hit\",\n      \"hit\": 2,\n      \"location\": { \"url\": \"file:///path/to/cli.js\", \"line\": 5, \"column\": 3 },\n      \"result\": {\n        \"type\": \"number\",\n        \"value\": 55574528,\n        \"description\": \"55574528\"\n      }\n    },\n    {\n      \"event\": \"completed\"\n      // The final entry is always a terminal event, for example:\n      // 1. { \"event\": \"completed\" }\n      // 2. { \"event\": \"miss\", \"pending\": [0, 1] }\n      // 3. {\n      //      \"event\": \"timeout\",\n      //      \"pending\": [0],\n      //      \"error\": {\n      //       \"code\": \"probe_timeout\",\n      //       \"message\": \"Timed out after 30000ms waiting for probes: app.js:10\"\n      //      }\n      //    }\n      // 4. {\n      //      \"event\": \"error\",\n      //      \"pending\": [0],\n      //      \"error\": {\n      //       \"code\": \"probe_target_exit\",\n      //       \"exitCode\": 1,\n      //       \"stderr\": \"Error: boom\",\n      //       \"message\": \"Target exited with code 1 before probes: app.js:10\"\n      //      }\n      //    }\n      // 5. {\n      //      \"event\": \"error\",\n      //      \"pending\": [1],\n      //      \"error\": {\n      //       \"code\": \"probe_failure\",\n      //       \"probe\": 0,\n      //       \"stderr\": \"...\",\n      //       \"message\": \"Target process exited during probe evaluation before probes: app.js:12. If the failure repeats, review the probe expression.\",\n      //       \"details\": { \"lastCdpMethod\": \"Debugger.evaluateOnCallFrame\" }\n      //      }\n      //    }\n    }\n  ]\n}\n</code></pre>",
              "displayName": "Probe output format"
            },
            {
              "textRaw": "Output and exit codes",
              "name": "output_and_exit_codes",
              "type": "module",
              "desc": "<p>Probe mode only prints the final probe report to stdout, and otherwise silences\nstdout/stderr from the child process. When the probing session ends,\nthe probing process typically exits with code <code>0</code> and prints a final report to\nstdout. If the child process exits with a non-zero code before the probe\nsession ends, or the probe session cannot complete for another reason, the\nfinal report records a terminal <code>error</code> event.</p>\n<p>When <code>error.code</code> is <code>'probe_failure'</code> or <code>'probe_timeout'</code>, the probing process\nexits with a non-zero code, indicating recorded hits may be incomplete.\nIn this case, <code>error.message</code> will contain recovery hints, and <code>error.probe</code>,\nwhen present, is an index into the report's <code>probes</code> array that identifies\nthe possible culprit probe on a best-effort basis to help guide debugging.</p>\n<p>Invalid arguments and fatal launch or connect failures may cause the\nprobing process to exit with a non-zero code and print an error message\nto stderr without a final probe report.</p>",
              "displayName": "Output and exit codes"
            },
            {
              "textRaw": "Probing multiple expressions at the same execution point",
              "name": "probing_multiple_expressions_at_the_same_execution_point",
              "type": "module",
              "desc": "<p>When multiple <code>--probe</code>/<code>--expr</code> pairs share the same <code>--probe</code>, the\nexpressions will be evaluated on the same pause in the order they appear\non the command line.</p>\n<pre><code class=\"language-js\">// app.js\nconst x = { x: 42 };       // line 2\nconst y = { y: 35 };       // line 3\nconst z = { ...x, ...y };  // line 4\n</code></pre>\n<pre><code class=\"language-console\">$ node inspect --probe app.js:4 --expr 'x' --probe app.js:4 --expr 'y' -- app.js\n</code></pre>\n<p>Prints</p>\n<pre><code class=\"language-text\">Hit 1 at file:///path/to/app.js:4:1\n  x = {x: 42}\nHit 1 at file:///path/to/app.js:4:1\n  y = {y: 35}\nCompleted\n</code></pre>\n<pre><code class=\"language-console\">$ node inspect --probe app.js:4 --expr 'x' --probe app.js:4 --expr 'y' --json --preview -- app.js\n</code></pre>\n<p>Prints</p>\n<pre><code class=\"language-json\">{\"v\":2,\"probes\":[{\"expr\":\"x\",\"target\":{\"suffix\":\"app.js\",\"line\":4}},{\"expr\":\"y\",\"target\":{\"suffix\":\"app.js\",\"line\":4}}],\"results\":[{\"probe\":0,\"event\":\"hit\",\"hit\":1,\"location\":{\"url\":\"file:///path/to/app.js\",\"line\":4,\"column\":1},\"result\":{\"type\":\"object\",\"description\":\"Object\",\"preview\":{\"type\":\"object\",\"description\":\"Object\",\"overflow\":false,\"properties\":[{\"name\":\"x\",\"type\":\"number\",\"value\":\"42\"}]}}},{\"probe\":1,\"event\":\"hit\",\"hit\":1,\"location\":{\"url\":\"file:///path/to/app.js\",\"line\":4,\"column\":1},\"result\":{\"type\":\"object\",\"description\":\"Object\",\"preview\":{\"type\":\"object\",\"description\":\"Object\",\"overflow\":false,\"properties\":[{\"name\":\"y\",\"type\":\"number\",\"value\":\"35\"}]}}},{\"event\":\"completed\"}]}\n</code></pre>",
              "displayName": "Probing multiple expressions at the same execution point"
            },
            {
              "textRaw": "Selecting the probe location",
              "name": "selecting_the_probe_location",
              "type": "module",
              "desc": "<p>The expressions are evaluated in the lexical scope of the probe location when\nexecution reaches it. Avoid probing a variable declared by <code>let</code> or <code>const</code> at its\ndeclaration site, as this leads to a <code>ReferenceError</code> caused by\naccessing the variable in its temporal dead zone (TDZ).</p>\n<pre><code class=\"language-js\">// app.js\nconst x = 42;        // line 2\nconsole.log(x);      // line 3\n</code></pre>\n<pre><code class=\"language-console\">$ node inspect --probe app.js:1 --expr 'x' app.js\nHit 1 at file:///path/to/app.js:1:1\n  [error] x = ReferenceError: Cannot access 'x' from debugger\n  ...\nCompleted\n</code></pre>\n<p>Instead, probe at a location where the variable is already initialized:</p>\n<pre><code class=\"language-console\">$ node inspect --probe app.js:3 --expr 'x' app.js\nHit 1 at file:///path/to/app.js:3:1\n  x = 42\nCompleted\n</code></pre>\n<p>The <code>&#x3C;file></code> argument is matched as a path suffix of every loaded\nscript URL, anchored on a path separator. Passing only a basename\nmatches every loaded script with that basename, similar to how native\ndebuggers typically match breakpoints, while passing a partial path\nnarrows the match. Given:</p>\n<pre><code class=\"language-text\">project/\n  - src/utils.js\n  - lib/utils.js\n</code></pre>\n<p><code>--probe utils.js:10</code> binds to <em>both</em> files and produces one hit per match.\nEach hit carries its own <code>location</code> field identifying where the expression\nwas actually executed, so consumers can attribute the result to one of the\ntwo files accurately. To disambiguate at bind time, specify a fuller path\nthat only matches the intended file:</p>\n<pre><code class=\"language-console\">$ node inspect --probe src/utils.js:10 --expr 'x' main.js   # matches only src/utils.js\n</code></pre>",
              "displayName": "Selecting the probe location"
            }
          ],
          "displayName": "Probe mode"
        },
        {
          "textRaw": "Advanced usage",
          "name": "advanced_usage",
          "type": "misc",
          "modules": [
            {
              "textRaw": "V8 inspector integration for Node.js",
              "name": "v8_inspector_integration_for_node.js",
              "type": "module",
              "desc": "<p>V8 Inspector integration allows attaching Chrome DevTools to Node.js\ninstances for debugging and profiling. It uses the\n<a href=\"https://chromedevtools.github.io/devtools-protocol/\">Chrome DevTools Protocol</a>.</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>Using the <code>--inspect</code> flag will execute the code immediately before debugger is connected.\nThis means that the code will start running before you can start debugging, which might\nnot be ideal if you want to debug from the very beginning.</p>\n<p>In such cases, you have two alternatives:</p>\n<ol>\n<li><code>--inspect-wait</code> flag: This flag will wait for debugger to be attached before executing the code.\nThis allows you to start debugging right from the beginning of the execution.</li>\n<li><code>--inspect-brk</code> flag: Unlike <code>--inspect</code>, this flag will break on the first line of the code\nas soon as debugger is attached. This is useful when you want to debug the code step by step\nfrom the very beginning, without any code execution prior to debugging.</li>\n</ol>\n<p>So, when deciding between <code>--inspect</code>, <code>--inspect-wait</code>, and <code>--inspect-brk</code>, consider whether you want\nthe code to start executing immediately, wait for debugger to be attached before execution,\nor break on the first line for step-by-step debugging.</p>\n<pre><code class=\"language-console\">$ node --inspect index.js\nDebugger listening on ws://127.0.0.1:9229/dc9010dd-f8b8-4ac5-a510-c1a114ec7d29\nFor help, see: https://nodejs.org/learn/getting-started/debugging\n</code></pre>\n<p>(In the example above, the UUID dc9010dd-f8b8-4ac5-a510-c1a114ec7d29\nat the end of the URL is generated on the fly, it varies in different\ndebugging sessions.)</p>",
              "displayName": "V8 inspector integration for Node.js"
            }
          ],
          "displayName": "Advanced usage"
        }
      ]
    }
  ]
}