Reputation: 5468
I have been seeking solutions for debugging Node.js based web application from days. I had tried to debug with Eclipse + Chrome debugger plugin but failed, I posted the error in this session 'Failed to get tabs for debugging' when trying to debug NodeJs with chrome debugger for Eclipse, but could not find an answer.
However, as Node.js is so popular, I have no doubt that a lot developers have the solution for debugging Node.js server JavaScript code. I appretiate if you could share me your solution of setting up an IDE (edit and debug) for Node.js server JavaScript code, or at least how to debug it.
Upvotes: 2
Views: 1578
Reputation: 1
Try to use Weinre (WEb INspector REmote). It's a node app help you debug UI, log for web app on devices. It hope it can help you.
Upvotes: 0
Reputation: 4457
There are several tools to debug a node application. A great ressource has been postet on Github recently.
A simple debugging setup might be just adding a breakpoint to your code and start node in debug mode like this:
Example code with use of debugger
, a manual breakpoint.
app.get('/foo', function(req, res) {
var something = 123;
debugger; // execution stops if this point is reached
foo(something);
});
Start node in debug mode:
$ node debug app.js
Once you started the application in debug mode you use the application (e.g., navigate to the ressource with your browser) and once a breakpoint occurs, the execution stops and you have a debugger environment in your terminal.
Upvotes: 1
Reputation: 17535
I would suggest using node-inspector
. Here is a good tutorial for setting it up. It allows you to use a browser tab to look at your code, set breakpoints, and step through it. Additionally, you can start node with the flag --debug-brk
and it will insert a break point on the first line, if you need to debug something that happens on startup.
Upvotes: 1