Debug applications in Nodejs

Asked

Viewed 512 times

0

What are the best tools to be used in debugging applications?

  • 6

    Although I answered, I am voting against the question as it is information easily found in the Ode documentation. If you have a more specific question about using Node Bugger, please edit the question.

  • I find the question very pertinent as debugging on the console often breaks the branch, but having a professional tool for it is essential when developing robust applications.

  • 1

    @Danielt.Sobrosa The problem with this question is that it’s too comprehensive. Perhaps a better question would be: "How to use Node Debugger to debug Node applications on the console?" and the other equivalent versions. Note that your answer has gotten big and still needs to skip details -- for example, you had to assume that OP knows how to debug an application using a debugger.

  • Although the question was very well answered, I would just like to add: I really like to use https://codenvy.com/ to develop in Ode. The IDE is in the cloud and already has everything I need to work with. In my case it fits well because I don’t professionally develop on Node.

  • It’s true. But I had the same problem when I started on Ode, I didn’t know what tool the community was using. And I still do not know, but I found one that fell like a glove in my way of working. So I found valid the question.

  • I appreciate the answers and I agree that I could have been more specific, but when doing quick searches I had not found anything that seemed to me "the most used". The question was more to know opinions.

  • 1

    I find the question pertinent. Hours, if the same author conducted a survey on and did not find a satisfactory answer, why not ask here? More people who are starting at Nodejs can get to this site by asking their question.

  • 2

    I consider the question valid, however I do not find it interesting to use expressions like "in your opinion" since it takes the objectivity of the answer. Still, I think it should be reopened.

Show 3 more comments

4 answers

11


The Node itself already has a debug tool, just run your Node module as follows:

node debug nome_do_seu_modulo

Follow the documentation to see how it works: http://nodejs.org/api/debugger.html

But there is the node-inspector which allows you to use the browser to debug. Simply startar the Debugger and access the url in the browser. Follow documentation: https://github.com/node-inspector/node-inspector


Using the Inspector Node

Install via npm:

$ npm install -g node-inspector

Start the Debugger:

node-inspector

Launch your app in debug mode:

$ node --debug your/short/node/script.js

Or start by telling you to pause on the first line:

$ node --debug-brk your/short/node/script.js

Go to the url:

http://127.0.0.1:8080/debug?port=5858

Okay, just debug in the browser!


Using the Node Debugger

Launch your app in debug mode:

node debug meu_app

At that point Debugger will stop at the first line, then just debug. Follow some commands:

cont, c - Continue execution
next, n - Step next
step, s - Step in
out, o - Step out
pause - Pause running code (like pause button in Developer Tools)

It is also possible to monitor the value of variables:

watch( "nome_da_variavel")

This way, with each step that is given, it will print in the console the value of the observed variables.

It is also possible to write expressions, just use the command repl and type expressions. To return type Ctrl+C.

See the documentation to have more details about the commands.

  • It’s really simple to do and gives immense productivity gain when debugging an application.

5

3

The Node has a Debugger, that you spin like this:

node debug myscript.js

3

Browser other questions tagged

You are not signed in. Login or sign up in order to post.