sudo npm install -g node-inspector to install node-inspector. If it tells you that it couldn't install some "blazing fast native extensions" don't worry: it'll still work fine.
Now you'll need two terminal windows:
1) Run the program in debug mode:
node --debug-brk test.js
2) Start the debugger:
--debug-brk causes the node program to break immediately
--debug-brk and --debug options for node
When you use the --debug option you can set a breakpoint using
debugger;. If your code finishes running before you can start node-inspector and go to the debugging page in the browser --debug-brk will set a breakpoint right at the beginning of the program.
Here's an example for using --debug:
var a = 5;
a += 8;
If you're getting 'connect ECONNREFUSED'
This probably means that you've tried to access the inspector in the browser while your node.js script isn't running. So first start your node process with --debug-brk and then run node-inspector.