Technical Articles
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
Hi Sergio,
For some reason, my breakpoint is not getting hit. Debugger is active, attached. I can see the console logging out from my XSJS module, user XSA_DEV. Everything seems to be working however the debugger is not stopping at my breakpoint!
Supposed to be something very straightforward but somehow it's not working.
Any ideas?
did your module build successfully?
is it running?
did you check the url to make sure it is going to the right path?
Yes - the module is working fine (I can see the output, simple "Hello World" XSJS). I also added console.log output which I can see as well.
I think it has to do with the Websocketclient.js but can't nail it down. I've added SSL certificate to the root store, have a secure browser connection but the breakpoint is not getting hit.
is you added SSL cert - make sure your module is running against https instead of http (browser url window)
Yes module is running against HTTPS (I can see the module is being called, can see the output) but the breakpoint in the attached debugger is not getting hit.
on the debugger icon (right hand nav) -- do you have more than 1 active session? are you able to select one, or switch to another to see if that would bring the correct session and be able to stop the debugger ?
I only have one. Clean install just implemented a simple XSJS to test the debugger. Session is getting attached to the debugger - all ok. However if I run the module from a different session the debugger doesn't stop at my breakpoint.