The first kind of

  1. Open thevscodeThe built-in terminal is selected in the upper right corner JavaScript Debug Terminal

  1. Break points in code (need to be entered at breakpointsdebuggerOr markingBreakpoint)
  2. The terminal can run the command

The second,

  1. MAC is selected by shortcut keysDebug: Toggle Auto AttachOpen,Auto Attach(This mode is required for Node versions greater than 12)
  2. Break points in code (need to be entered at breakpointsdebuggerOr markingBreakpoint)
  3. Terminal through commandnode --inspect index.jsExecute the code

The third kind of

Sometimes when looking at open source libraries and you want to view the source code with a breakpoint, you can configure the launch.json to specify the runtime execution environment

For example, package.json has scripts

For VScode debugging, configure launch.json as follows

Where runtimeExecutable specifies the runtime execution environment, which is NPM, and runtimeArgs specifies the execution parameter corresponding to the runtime execution environment, which is run dev.

Once configured, press F5 to start debugging, and NPM run dev is actually executed so that we can see the code execution at the source break point

More debugging tips can be found on vscode’s website

A fourth

ndb is an improved debugging experience for Node.js, enabled by Chrome DevTools

With NDB, as described on its website, NDB enhances the experience of debugging NodeJS by enabling a Chrome Devtools.

To use it, you need to install it. You can use NPM install -g NDB. After installing it, enter the debugger in the code where you need the breakpoint, and run NDB index.js

Nodejs debugger nodeJS debugger nodeJS Debugger nodeJS Debugger nodeJS Debugger nodeJS Debugger