How do you debug a node.js application?

I am working on a node.js application and sometimes it freezes. I assume this is because the user code stream is frozen. This seems to happen after about 5 minutes of use, but I have no idea why. Are there any tools that let you know where he came to a standstill? Besides adding a log to each line.

Updated to add more information ....

I added some trace statements and narrowed them down to the following code:

exports.addLocationToRoute = function(req, res) { console.log("27"); console.log(req.body); var queryConfig = { text: "INSERT INTO route_locations (route_id, location_id, order_id) VALUES ($1, $2, $3);", values: [req.params.id, req.body.locationId, req.body.order] }; pg.connect(conString, function(err, client) { console.log("28"); ... 

I see 27 output in the trace, but not 28. Is there a way to see why it is frozen between these two points?

update 2:

I just tried to play again, and it froze at another point in the code, but at this point it also calls

 pg.connect(conString, function(err, client) { 
+4
source share
2 answers

I am using JetBrains WebStorm IDE to develop Javascript. It has full Node support, which means you can set breakpoints and trace your code. However, WebStorm is not free. You can also see an older topic in Node debugging: How to debug Node.js applications?

There, the answer is accepted about using Chrome development tools , but I would prefer to use the more popular node-inspector answer method for debugging.

+4
source

You probably want to put the node in the --debug mode and analyze it using the node-inspector .

When the code is locked in any place, you can pause the execution using the pause button ( http://pix.am/LYZz/ ) and check the stack trace to find locks.

0
source

Source: https://habr.com/ru/post/1402319/


All Articles