David Marr

  • Archive
  • RSS
  • Ask me anything

Debugging with NodeJS and Expresso

NodeJS

git clone https://github.com/joyent/node.git

Expresso

git clone https://github.com/visionmedia/expresso.git

After installing NodeJS and Expresso you will have to make a change to your Expresso file to allow for debugging.

Add the following statement to your code to set a breakpoint in the debugger:

debugger;

Next, run the following to start up the NodeJS debugger and use Expresso for your unit tests.

Using TextMate

mate $(which expresso)

Using vim

vim $(which expresso)

Change the first line to read:

#!/usr/bin/env node debug

Executing your tests with expresso now uses the node debugger.*

expresso test.js

For those looking for a browser based debugging environment, check out node-inspector.

Node Inspector

git clone https://github.com/dannycoates/node-inspector.git

To get this to work with Expresso, I had to change the hashbang to be:

#!/usr/bin/env node —debug-brk
node-inspector &

Now, running expresso test.js will open your file in a web browser for debugging. You will have to point your browser to node-inspector and you can explore your breakpoints and watch variables just like you were in WebKit.

Happy coding, twitternets!

* There are mixed feelings about this in the develosphere, as debugging unit tests is a bit like betting on black /and/ red. I am illustrating how to do it, not advocating its use. Personally I think its better to rely on the unit testing framework to surface errors but stepping through with debugger; statements is sometimes the only way to dive deep into the problem.

    • #nodejs
  • 11 months ago
  • 4
  • Permalink
  • Share
    Tweet

4 Notes/ Hide

  1. promontoryop3 liked this
  2. kamykaze77 reblogged this from dmarr
  3. kamykaze77 liked this
  4. 3k38leo liked this
  5. dmarr posted this
← Previous • Next →

About

Check out my about.me profile!

Twitter

loading tweets…

  • RSS
  • Random
  • Archive
  • Ask me anything
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr