Debugging Node JS code in XSA
Hello community. Here is another important blog in the series of #XSA development. This one is showcase the steps needed to set up some debugging sessions on the #WebIDE on #HANA #XSA.
if you prefer the spanish version of the same blog
- Start by opening a nodejs file
- Set up some break points
- Click the bug icon on the right navigation menu
- Run your node js module – top left play icon to run your module (assuming it built successfully)
- Click on the attach debugger icon so that we can attach our session to a running session
*if your node module is not running, the drop down will be empty, otherwise, a dialog box opens with the debug targets – I selected the run (node) script session to attach my debugger
If everything goes well, then you will see the debugger attached message
6) Spend a few seconds to see the debugger panel – it has the call stack where you can see execution, the variables (local, scoped, closures), the expressions – you can evaluate statements at run time, and the breakpoints section down below to see all the breakpoints you set.
7) Next, Run the ui module url with the path to the svc, which you set up on the xs-app.json file.
If you do it correctly, your browser window will spin, (switch windows to the web ide) and the debugger will stop on your first breakpoint. If you set up a breakpoint (like I did initially) on the index.js the breakpoint will not stop there since that file only works as a request router, so make sure you set up a breakpoint in your service implementation.
Notice the debugger has a message – debugger suspended since you are now stepping through code.
You can either use the arrows on the top right or your keyboard to go to the next line or jump or resume execution.
This is a very neat and extremely easy way to see what is happening on your services.
When you are done debugging, do not forget to pause and detach your debugging session.
If you spend a little while in the debugger, your browser request will get a gateway timeout – this is ok since you know you were idle on the request longer than the timeout range is.
What do you think? Simple enough huh? Again, please provide your comments and/or questions. Good luck