How to debug a nodemon project in VSCode

后端 未结 6 1852
醉酒成梦
醉酒成梦 2021-02-04 01:19

I have a NodeJs project and I run it using nodemon,
I wish to run it in debug mode for development tasks, but I am unable to do so.

I found that I\'ll need to ad

6条回答
  •  没有蜡笔的小新
    2021-02-04 02:14

    As @the Geek proposes,

    1. You should modify launch.json as follows:

      {
          "version": "0.2.0",
          "configurations": 
        [    
          {
              "type": "node",
              "request": "attach",
              "name": "Attach by Process ID",
              "processId": "${command:PickProcess}"
          }
        ]
      }
      
    2. Start server "npm run dev" (as you can see, in "request" property, we set to attach. So we have to run the server firstly and then attach the debugger).

    3. Click on the left side of vscode in the bug-like icon. On top you will see the small green play icon. Click on the dropdown arrow right of it and select "Attach by process ID".

    4. Click on the play icon and then a bar on the bottom of vscode should turn dark orange. Now try making a request. Breakpoints will be hit correctly!

提交回复
热议问题