node.js Introduction to debugging


Introduction to 1-1 inspector

Git bash common commands

  • mkdir testNew folder
  • cd testEnter folder
  • cd ../Enter parent folder
  • lsLists the files and folders under the current folder
  • Code the name of the folder in the current directoryThe corresponding project can be opened through a global variable code provided by vscode

Vs Code for breakpoint debugging

Press F5 to start a websocket service for debugging, and the following will be printed on the debugging console:

D:\Program Files\nodejs\node.exe --inspect-brk=24775 app.js
Debugger listening on ws://
For help, see:

The corresponding HTTP service is: JSON at the end to view the corresponding meta informationhttp://

1-2 activation debugging

node --inspect app.jsAdd — inspect at runtime to activate debugging

Using express to build a service startup debugging

  1. npm initInitialize a package manager and specify the entry file( app.js )
  2. npm install express --saveInstall express module
  3. In the entry file app.js Write service code in
const express = require('express')
const app = express()

app.get('/', (req, res) => {
  res.send('hello world !')

app.listen('3000', () => {
  console.log ('Program runs on port 3000 ')
  1. node --inspect app.jsRun the command to start debugging

Note: you need to set vscode, search for attach in the settings, and change the value of debug > node: Auto attach to on

1-3 ~ 4 debug client – chrome devtools

Start debugging client

  • Method 1:

    1. Input in the Chrome browser chrome://inspect
    2. Select devices
    3. Click Configure… To configure done
    4. Then click inspect under target
  • Method 2:
    The devtoolsfrontendurl in meta information can also be opened directly in the browser
    View meta information
  • Law 3:
    Open the browser developer tool and click the green icon in the upper left corner to enter
  • Law 4:
    Using the debugging function of vscode

1-5 debug client vscode

  • Start method: shortcut key F5
  • to configure: launch.json
  • Print parameter list in node:console.log(process.argv)

Introduction of 1-6 command line parameters

  • Official documents

This work is original and adopts the “signature – noncommercial use – no deduction 4.0 international” license agreement