Skip to content

Instantly share code, notes, and snippets.

@kamal-hossain
Last active January 12, 2021 01:39
Show Gist options
  • Save kamal-hossain/98f632de0bf13e85e72887c8c330e799 to your computer and use it in GitHub Desktop.
Save kamal-hossain/98f632de0bf13e85e72887c8c330e799 to your computer and use it in GitHub Desktop.
For

Debugging ideas

launch.json file should be saved on ${workspaceFolder}\.vscode\.launch.json

{
/*
// ##############################
// FOR nodejs app
// tested on:
//node v12.18.1,
// npm v6.14.5,
// vscode::
// Version: 1.52.1 (user setup),Commit: ea3859d4ba2f3e577a159bc91e3074c5d85c0523,
// Date: 2020-12-16T16:34:46.910Z, Electron: 9.3.5, Chrome: 83.0.4103.122, Node.js: 12.14.1
// ,V8: 8.3.110.13-electron.0, OS: Windows_NT x64 10.0.19041
##############################
*/
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "YOUR APP NAME",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\server.js", // entry point of the app
"restart": true, // for nodemon
"runtimeExecutable": "nodemon", // nodemon must be installed globally
"console": "integratedTerminal" // will use the vscode intregated terminal
}
]
}

Nodejs debugging in vscode

Create a launch.json file if no file was created

  • Press ctrl+shift+D and create a launch.json` file
  • Configure the entry point of the server e.g. "program": "${workspaceFolder}\\server.js",
  • Add nodemon configuration if needed (view the launch-.-json file attached in this gist for example)

Attach the debugger with nodejs app when starting by

  • Go to top menu => Run > Start Debugging
  • Select Node.js (preview)
  • Select Run Script: start
  • View the console for debugger attached
  • Tested in the following versions:

or use lunch.json from here

See variables values in breakpoint (nodejs)

  • add a breakpoint in line
  • hover over variables or type varible name in DEBUG CONSOLE

    you can also run prototype functions like splice()

TypeScript debugging in vscode

  • Add brekpoint in TypeScript file to inspect via vscode debugger and Debugger for Chrome

    • Install Debugger for Chrome extension in vscode
    • F9 to add breakpoint
    • Set "sourceMap": true, in tsconfig.json
    • Go to Run > Start Debugging
    • Select environment Chrome (it won't appear with chrome extention)
    • In launch.json file set url to specefic port where developemnt server is running e.g. (http://localhost:3000)
    • Make sure webRoot is correct
    • Run tsc in bash
    • Now Start debugging with the launch.json is correctly configured
    • Now see the VARIABLES in left side of vscode
  • Resources https://code.visualstudio.com/docs/typescript/typescript-debugging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment