Debug a script

The Script Editor provides a debugger to debug server scripts to troubleshoot code, for example, to inspect the value of variables, in real time.

The Script Editor debugger uses the Node.js V8 inspector to enable the real-time debugging developer experience, necessitating extra memory requirements. Take into account the following to conserve and better utilize memory usage:

  • Avoid debugging in a production environment unless absolutely necessary

  • Consider using logging or tracing instead of live debugging for memory-critical applications

Prerequisites

  • You have a script open in your project.

Procedure

  1. Select the Debug icon.

    Result: The debugger runs and pauses at the first line of the script. The Scope pane opens, and displays blocks of statements (block), functions with corresponding enclosed references (closures), local variables (local), and global variables (global) for inspection within the selected scope associated with the function. The script output pane displays the execution of the script process and indicates the attachment of the debugger in the process.

    To heighten security, passwords or secrets contained in blocks of statements (block) are returned as empty in the Scope pane.
  2. In the script editing pane, to move from the highlighted line of code to the next line of code, select the Step Over icon (or the shortcut key F10).

  3. To move to method calls and variables that correspond to the highlighted line of code, select the Step Into icon (or the shortcut key F11). For example, you can step into an npm module to inspect its source code in a separate debug tab.

  4. To leave the current scope of the highlighted line of code and move to the last return statement from where the function was called from, select the Step Out icon (or the shortcut keys Shift + F11).

  5. To resume debugging of the script until the next line of the script, select the Resume icon (or the shortcut key F8).

  6. In the Evaluate Expression pane, to evaluate arbitrary expressions corresponding to the scope of the debugger, enter an expression to be considered when running the debugger. To evaluate previously entered expressions, use the arrow keys in the input field to cycle through expressions.

Results

  • You have run the debugger for a script and can inspect your code according to the relevant use case.