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
