Reputation: 2235
I have written an application in node.js. In the main module, I create various promises using cujojs' when module and push them into an array and use when.all().then() to send a happy message when they are all fulfilled. Some of the promises are resolved when certain messages are received over a WebSocket connection. When the WebSocket messages arrive in a certain order, I get the happy message. When the messages arrive in a different order, I don't get the happy message.
So I want to look at the array of promises and other variables in the main module. Simply invoking the debugger results in a "No Frames" error, so I set up a dummy "heartbeat" function that gets invoked once per second through setInterval. Then when I set a breakpoint in the heartbeat function and tried to look at the array of promises, the debugger told me that it was undefined (should be a module-wide variable!). So I put a var pa = promises_array
line in the heartbeat function. Then I tried to use when's inspect method in repl as follows:
debug> repl
Press Ctrl + C to leave debug repl
> for( p in pa ){ console.log( p.inspect().state }
And it said TypeError: Object 0 has no method 'inspect'
So I'm not sure what is going on. Why can't I see the variables in the module when I set a breakpoint in the module?
Upvotes: 0
Views: 1820
Reputation: 2235
While it is probably a great idea to use node-inspector, it's going to take me a while to get it set up on my platform, and I just discovered that the actual correct answer to my question is I should have typed the following into repl
for( p in pa ){ console.log( 'marker '+p+' is '+pa[p].inspect().state ); }
In other words, I'm an idiot for trying to invoke a method on the index p instead of the value of the array at index p :"(
Upvotes: 0
Reputation: 1280
Try using Node Inspector.
Node Inspector allows you to debug your Node.js code in pretty much the same way you would debug a front-end application in Chrome Developer Tools, including using debugger statements and setting breakpoints. You can walk through your promise step by step as it executes.
Upvotes: 1