BigPun86
BigPun86

Reputation: 2686

How can i debug a nodejs backend with node-inspector?

I am trying to debug my backend and i am not really sure if i am doing it the correct way.

I have set up the debugging as follows:

Node 6.9.1 and node-inspector 0.12.8

  1. open a command prompt and run the following command:

    node-inspector --web-port=3030 (server app port)

  2. open another command prompt and run the following command:

    node --inspect --debug-brk server.js

  3. browse to the given URL in the second command prompt log on screen

  4. press F8 to make the server run
  5. eventually put some others breakpoints
  6. browse on another tab to your app (address and port defined in 1-)
  7. see server execution stops on breakpoints defined on step 5.

Now when i run node --inspect app.js and everything looks good so far. I can debug the first start in the app.js. But if I want to debug an endpoint with POSTMAN, I get the error "Cannot POST /api/trainingsWeek". The endpoint works if I don't debug.

Do I have to take another address? Or another tool than POSTMAN? ANd what is the difference between node --inspect app.js and node-debug

GitHub Issue

enter image description here

enter image description here

UPDATE

This was my stupid mistake :P Here is the solution: https://github.com/node-inspector/node-inspector/issues/907#issuecomment-280620108

Upvotes: 1

Views: 4673

Answers (1)

ddg
ddg

Reputation: 56

I use VS Code to debug. I guess you don't need node-inspector, it will run with the integrated debugger from Node. To get it running, open your project and the debug view. There should be no configuration available. Click on the little wheel -> choose node.js as the environment.

enter image description here

After that the standard json will be created and looks like this:

enter image description here

And then click on the play button with the selection start programm. With that the debugging should run. Now you can use POSTMAN with the same url when you just run your server and the debugger from VS Code should hit your breakpoint.

Upvotes: 3

Related Questions