Master VS Code launch.json: Debug Node.js and Chrome with Ease
This guide explains why developers love Google DevTools, introduces VS Code's launch.json for configuring debugging sessions, covers REPL basics, provides practical examples for Node.js and Chrome debugging, and details every launch.json option with descriptions, types, defaults, and sample code.
Google Developer Tools are popular because they simplify debugging and support real‑time console output; combined with remote Node.js debugging they become very powerful. VS Code’s launch.json lets you bring those capabilities into the editor, enabling direct debugging from your coding environment.
launch.jsonis a JSON file used by VS Code to define debugging configurations such as the debugger type (Node.js, Chrome, etc.), launch arguments, environment variables, and can be combined with tasks.json for task automation. It usually resides in the project’s .vscode folder and is generated and managed by VS Code.
REPL (Read‑Eval‑Print Loop) is an interactive console that executes code snippets instantly, which is especially useful for quick testing and debugging complex logic. VS Code includes built‑in REPL support, and when used with launch.json it greatly improves the development experience.
My Example
Below are some configuration use cases.
Custom launch command with argument forwarding (the -- token passes subsequent parameters to npm):
{
"version": "0.2.0",
"configurations": [
{
"command": "npm run review -- --xxxxx",
"name": "debug review",
"cwd": "${workspaceFolder}/packages/code-review-gpt",
"request": "launch",
"type": "node-terminal"
}
]
}Using runtimeArgs:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Egg Debug",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "debug", "--", "--inspect-brk"],
"console": "integratedTerminal",
"restart": true,
"autoAttachChildProcesses": true
}
]
}If you prefer not to configure manually, you can install the JavaScript Debugger extension.
Select "Debug npm script" to choose the script you want to debug.
launch.json Configuration Items Explained
The launch.json file defines debugging settings; each field controls the debugger’s behavior. Below are common top‑level items.
Top‑Level Items
version
Description: Specifies the launch.json file version.
Type: string Default: "0.2.0"
Required: Yes
Example:
{
"version": "0.2.0",
"configurations": []
}configurations
Description: An array containing one or more debug configurations.
Type: array Default: None
Required: Yes
Example:
{
"version": "0.2.0",
"configurations": [
{ /* specific configuration */ }
]
}Other Configuration Items
program
Description: Path to the program entry file to debug.
Type: string Default: None
Required: Usually yes
Example:
{
"program": "${workspaceFolder}/app.js"
}cwd
Description: Current working directory.
Type: string Default: ${workspaceFolder} Required: No
Example:
{
"cwd": "${workspaceFolder}"
}env
Description: Environment variable definitions.
Type: object Default: None
Required: No
Example:
{
"env": {
"NODE_ENV": "development"
}
}preLaunchTask
Description: Task to run before launching the debug session.
Type: string Default: None
Required: No
Example:
{
"preLaunchTask": "build"
}postDebugTask
Description: Task to run after the debug session ends.
Type: string Default: None
Required: No
Example:
{
"postDebugTask": "cleanup"
}outFiles
Description: Glob patterns for generated JavaScript files, used with source maps.
Type: array Default: None
Required: No
Example:
{
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
}sourceMaps
Description: Enable source‑map support for TypeScript or Babel compiled code.
Type: boolean Default: false
Required: No
Example:
{
"sourceMaps": true
}restart
Description: Automatically restart the debugger if the session terminates unexpectedly.
Type: boolean Default: false
Required: No
Example:
{
"restart": true
}console
Description: Choose the console type: internalConsole, integratedTerminal, or externalTerminal.
Type: string Default: internalConsole Required: No
Example:
{
"console": "integratedTerminal"
}Debugger‑Specific Options
Different debuggers have their own additional fields.
Node.js Debugger
runtimeExecutable
Description: Path to the Node.js executable; defaults to the node found in PATH.
Type: string Required: No
Example:
{
"runtimeExecutable": "/usr/local/bin/node"
}runtimeArgs
Description: Command‑line arguments passed to Node.js.
Type: array Required: No
Example:
{
"runtimeArgs": ["--nolazy"]
}skipFiles
Description: Files or modules to skip during debugging, supports glob patterns.
Type: array Required: No
Example:
{
"skipFiles": ["<node_internals>/**"]
}Chrome Debugger
url
Description: URL of the page to debug.
Type: string Required: Yes when request is launch Example:
{
"url": "http://localhost:3000"
}webRoot
Description: Root folder of the web project.
Type: string Default: ${workspaceFolder} Required: No
Example:
{
"webRoot": "${workspaceFolder}/src"
}userDataDir
Description: Directory for Chrome’s user data.
Type: string Required: No
Example:
{
"userDataDir": "${workspaceFolder}/.vscode/chrome"
}Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Code Mala Tang
Read source code together, write articles together, and enjoy spicy hot pot together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
