Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I debug node modules?

I am looking into getting involved with the rather exciting node.js, but I'm trying to find ways to replace my current development environment.

At present, my best friend in PHPLand is FirePHP module for Firebug, which is a god send as far as debugging your PHP goes. What methods do I have at my disposal for debugging node code? Does it output errors and warnings like PHP can be set to?

like image 689
Mild Fuzz Avatar asked Jun 14 '11 08:06

Mild Fuzz


People also ask

Can you debug Nodejs?

There are a few ways you can debug your Node. js programs in VS Code: Use auto attach to debug processes you run in VS Code's integrated terminal. Use the JavaScript debug terminal, similar to using the integrated terminal.

Can I console log in node modules?

Logging using the console module. The most common way to log in Node. js is by using methods on the console module (such as log() ). It's adequate for basic debugging, and it's already present in the global scope of any Node.


1 Answers

There are multiple ways to debug node.

  • node debug app.js
  • node-inspector
  • console
  • util

Personally I use a lot of well place console.log, console.dir and util.inspect statements throughout my code and follow the logic that way.

Of course unit tests come hand in hand with debugging. Write tests that assert your code work. The unit tests will cover catching most of the bugs.

You must write unit tests for your node.js code. nodeunit is great for general testing.

If your using express as your web engine then use expresso

like image 100
Raynos Avatar answered Oct 11 '22 12:10

Raynos