Search code examples
node.jsrestdebuggingexpressnode-inspector

Debugging Node/Express RESTful API with node-inspector


I have seen many question about debugging a Node/Express application, but, it seem a node web application, not a RESTful server.

I have built a simple server, and it work perfect when start server with command node server.js. I can use Postman, or some other tools to invoke a GET/POST request.

After installing the node-inspector module, when I start a node-inspector debug with command node-debug server.js, it show me a webpage at http://127.0.0.1:8080/?ws=127.0.0.1:8080&port=5858 with inspector window.

Then, I use postman to invoke request again (which has invoked successfully earlier), but it show me a 404 error: Cannot GET /api/v1/user/login.

How can make a request to debugging server?


Solution

  • Here is my solution: Do not use node-debug *.js directly. Instead, open two terminals in your project. For example, I want to debug server-3.js, like the pictures down here. In one terminal, use node-inspector for debugging listening, and another use node --debug server-3.js

    enter image description here

    enter image description here

    after sending a request on postman: enter image description here

    you can see your debugging situation in your node-inspector window listening on port 5858:

    enter image description here

    I believe this is what you want to achieve.

    The latest update is that you can also resort to vscode, which has a plugin called "Debugger for Chrome" that has the debug function you want.

    enter image description here