liveBook · Manning

Node.js Inspector

As explained in Essential TypeScript 5, Third Edition

The Node.js debugger is the debugging facility integrated into Node.js for pausing, inspecting, and controlling JavaScript execution.

The Node.js Inspector pauses JavaScript execution so you can inspect application state, evaluate expressions, step through statements, and resume execution. It is useful when a running TypeScript application behaves incorrectly and static compilation alone cannot reveal why. section 6.0 section 6.5

A practical debugging workflow includes:

  • Configure Visual Studio Code to launch the compiled JavaScript entry point, usually under the dist folder. section 6.2.2
  • Pause execution with a breakpoint or the debugger statement. section 6.2.2 section 6.5
  • Inspect variables, set watches, step into or over statements, and evaluate JavaScript in the Debug Console. section 6.2.2
  • Use Chrome developer tools when remote control of the Node.js runtime is more convenient than the integrated debugger. section 6.2.4

Launching a short-lived program remotely

Run `node --inspect-brk dist/index.js` to start Node.js in remote debugger mode and halt immediately. Open `chrome://inspect`, configure the reported address and port, select the discovered runtime, and choose “inspect.” For a long-running server, use `--inspect` so the process can start before you connect. section 6.2.4

Listing 6.4 Changing the code path in the launch.json file in the .vscode folder
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}/dist/index.js",
            "outFiles": [
                "${workspaceFolder}/**/*.js"
            ]
        }
    ]
}

Use the launch.json listing to see how Visual Studio Code points the debugger at dist/index.js and locates generated JavaScript files. section 6.2.2

How Essential TypeScript 5, Third Edition covers it

How deep it goes
Provides setup, breakpoints, stepping, watches, console evaluation, and remote control, but does not detail inspector internals.
Examples
Uses launch.json, dist/index.js, debugger statements, and node --inspect-brk for short-lived programs.
What it assumes
Assumes compiled JavaScript output and introduces debugging through Visual Studio Code or Node.js rather than compiler analysis.
What you can do after
Diagnoses runtime behavior using breakpoints, state inspection, stepping, watches, console expressions, or remote developer tools.
How it connects
Connects Visual Studio Code, Chrome developer tools, source maps, breakpoints, and the debugger statement.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Essential TypeScript 5, Third Edition. The section links point to the parts of the book it draws on.