You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode调试器接收Postman请求时无法命中断点问题求助

Troubleshooting Nodemon Debugging for Your Express.js App

Hey there! I’ve been in your shoes before—trying to get VS Code debugging working with nodemon can feel like chasing your tail when it doesn’t click right away. Let’s walk through the most common fixes for this issue.

First, Double-Check Your launch.json Configuration

The most likely culprit is a small misconfiguration in your debug setup. Here’s a reliable template to compare against, and I’ll break down the critical parts:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Debug with Nodemon",
      "runtimeExecutable": "nodemon",
      // Replace this with your actual entry file (server.js, app.js, etc.)
      "program": "${workspaceFolder}/app.js",
      "restart": true,
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen"
    }
  ]
}

Key Checks for This Config:

  • program Path: Make sure this points directly to your Express app’s main entry file. If your file is in a subfolder (like src/server.js), update the path accordingly—${workspaceFolder}/src/server.js.
  • runtimeExecutable: If you’re seeing the full nodemon path in your terminal but debugging isn’t triggering, try using the absolute path to nodemon’s .cmd file (Windows-specific):
    "runtimeExecutable": "C:\\Users\\User\\AppData\\Roaming\\npm\\nodemon.cmd"
    
    If you installed nodemon locally (not globally), use the local path instead:
    "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/nodemon"
    

Verify Breakpoint & VS Code Settings

If the config looks right but breakpoints aren’t hitting:

  • Breakpoint Placement: Ensure your breakpoints are on lines of executable code—avoid comments, empty lines, or code that only runs under unmet conditions (like a conditional that never evaluates to true).
  • Auto Attach Toggle: Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac), search for "Auto Attach", and set it to "On" or "Smart". This helps VS Code automatically attach to the nodemon process when it restarts.

Try the "Attach" Debugging Mode Instead

Sometimes launching directly with nodemon can be finicky. Switch to attaching to a running nodemon process:

  1. First, start your app with nodemon in inspect mode from your terminal:
    nodemon --inspect app.js
    
  2. Update your launch.json with this attach configuration:
    {
      "version": "0.2.0",
      "configurations": [
        {
          "type": "node",
          "request": "attach",
          "name": "Attach to Nodemon",
          "port": 9229,
          "restart": true
        }
      ]
    }
    
  3. Start the "Attach to Nodemon" debug configuration in VS Code. This method is often more reliable because you’re connecting directly to the already running nodemon process.

Quick Sanity Checks

  • Update Dependencies: Run npm update -g nodemon to make sure you’re on the latest version—older versions can have compatibility issues with VS Code’s debugger.
  • Port Conflict: If the attach mode fails, check if port 9229 (the default Node.js debug port) is being used by another process. On Windows, run:
    netstat -ano | findstr :9229
    
    Kill the conflicting process if needed, then restart nodemon and the debugger.

Hopefully one of these fixes gets your debugging up and running smoothly!

内容的提问来源于stack exchange,提问作者marcuthh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:31:24