JavaScript debugger setup & example

This details how to setup and use the Javascript debugger.

To get the debugger you need to enable the debug mode like this:

"Set JS server debug mode"
thisSnippet database properties jsLinkSettings serverDebugMode: true.
  

If there are errors, it can be useful to stop the current link:

JSLinkApplication stop.
  

To check that the node process is running in the correct folder, take a look at this command:

var cwd = process.cwd();
cwd;
  

Consider this simple execution. Please inspect it:

let aVariable = 1;
aVariable + 40 + 1
  

And now inspect the same code with a breakpoint in the script:

let aVariable = 1;
debugger;
aVariable + 40 + 1
  

You get a debugger window that shows you the JavaScript code. You can step over or run and the execution will continue and still produce the result.

Now take a look at this slightly more complicated script that relies on an external file that also happens to contain a breakpoint:

let TestClass = require('../gtoolkit/testclass');
let testObject = new TestClass();
debugger;
testObject.factorial(3);
  

The external code can be found at:

FileLocator imageDirectory asFileReference / 'js' / 'src' / 'gtoolkit' / 'testclass.js'