Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS - a step-by-step debugger for NodeJS

I'm looking for effective way for step-by-step debugging NodeJS server code. At this moment I use dozens of console.log()'s and it's extremely hard. The perfect tool is one that would allow me to check the values of every variable in stack and trace my program line by line. Prefered OS = MacOS/Linux. Is it possible?

like image 941
f1nn Avatar asked Sep 28 '12 14:09

f1nn


People also ask

Is a debugging tool for Nodejs?

Node Inspector is a reliable debugger for Node. js apps based on the Blink Developer Tools – a powerful JavaScript debugging interface.

Which tools can be used to debug node JS application?

The V8 inspector integration allows attaching Chrome DevTools to Node. js instances for debugging by using the Chrome Debugging Protocol. In most cases, it makes sense to stop the execution of the application at the very first line of your codebase and continue the execution from that.

Which CLI option can you use to debug a node?

A minimal CLI debugger is available with node inspect myscript. js . Several commercial and open source tools can also connect to the Node.


4 Answers

Basically, Node.js is built on top of V8, so its debugging capabilities are also built on top of V8's debugging capabilities.

V8 has an included debugger which can be accessed via TCP on port 5858.

So basically all you need is a frontend which is able to connect to port 5858 and talk V8's debugging protocol.

One option is to use node-inspector which basically provides a debugging UI in your browser. Unfortunately, it does only work with Google Chrome and Apple Safari (which for me is no problem, but there may be others ;-)).

Another option is to use a plugin for Eclipse.

And, last but not least, the built-in debugger of Node.js (which always reminds me of MS-DOS's edlin) is also just a front-end for this TCP debugger, just a built-in one.

And of course, there are much more options ... these three were just the first three ones that came to my mind ;-)

like image 103
Golo Roden Avatar answered Oct 03 '22 04:10

Golo Roden


How about this?

You can try to test for Nodeclipse version 0.2.0 beta.

http://www.tomotaro1065.com/nodeclipse/

It will help you to debug node apps easily.

GENERATING OF EXPRESS PROJECT

Select the [File]-[New]-[Project] menu.
Select [Node]-[Express Project], and push [Next] button.
Enter [Project name], and push [Finish] button.

DEBUGGING

Open the JavaScript source files that you want to set breakpoints.
Double-click on the ruler at the left end of the line you want to set a breakpoint.
If you want to remove a breakpoint, double-click on the ruler again.
Select the main source file of Node Application on the Project Explorer, 
open the context menu by right-clicking, 
select the [Debug As]-[Node Application] menu.
like image 31
Tomoyuki Inagaki Avatar answered Oct 03 '22 03:10

Tomoyuki Inagaki


Use node-inspector to provide the node debugging environment you're looking for. It's fantastic.

like image 28
JohnnyHK Avatar answered Oct 03 '22 04:10

JohnnyHK


Check WebStorm. It is a great IDE, and also you can directly run your nodejs code, or connect to a debugging-enabled node process already running. In both cases, WebStorm provides what you are looking for: trace program execution line by line and on every line check the state of every variable.

like image 45
Sergio Cinos Avatar answered Oct 03 '22 04:10

Sergio Cinos