Debugging your Celigo scripts effectively can be done using an integrated development environment (IDE) like Visual Studio Code (VSCode). Instead of relying solely on console.log statements, a real debugger provides more powerful tools for troubleshooting your code. This guide will show you how to set up and use the debugger in VSCode to debug a Celigo Integrator script.
Setting Up the Debugger in VSCode
-
Open VSCode and Set Up a Workspace: Make sure you have VSCode installed on your computer. Open VSCode and create or open your workspace.
-
Create a New File: Create a new JavaScript file, for example, test.js, where you will write and debug your script.
-
Add Your Code: In the new file, add the following components:
-
The Function Input (JSON Object): Define the input object for your function. In code example: options.
-
The Function: Write the function you want to debug. In code example: function transform(options).
-
The Function Call: Call the function to execute it. In code example: transform(options);
Here's an example script:
const options = { record: { "thisIsATest": "test" } };
function transform(options) {
options.record.name = "Nuri";
console.log(options.record.thisIsATest);
console.log(options.record.name);
return options.record;
}transform(options);
-
-
Set a Breakpoint: To set a breakpoint, click in the gutter next to the line number where you want the execution to pause. A red dot will appear indicating the breakpoint.
-
Run the Debugger:
-
Click on the debug icon on the left sidebar.
-
Make sure your code file (for example test.js is open).
-
Select "Run and Debug" to start the debugging session.
-
-
When prompted to select an environment, choose "Node.js" because Celigo scripts typically run in a Node.js environment.
Installing Node.js: If you haven't installed Node.js yet, follow these steps:
-
Go to the Node.js website.
-
Download the installer for your operating system.
-
Run the installer and follow the prompts to complete the installation.
Node.js is essential for running JavaScript code outside of a browser, which is why it is needed for debugging Celigo scripts.
-
Navigating the Debugger:
-
Control Panel: Use the control panel at the top to step through the code (Step Over, Step Into, Step Out).
-
Variables Pane: On the left side, you can inspect variables and their values.
-
Hover to Inspect: Hover over variables in the code to see their current values.
-
-
Inspecting Variables: As you step through the code, you can inspect the state of your variables. This helps you understand how data is being manipulated within your function.
-
Continue Execution: After inspecting and making necessary changes, you can continue the execution of your script by clicking the play button. And you can stop it anytime using the stop button.
-
Debug Console: In the Debug Console window below you can see the console.logs.
By following these steps, you can efficiently debug your Celigo scripts using VSCode. This method provides a more comprehensive view of your code's behavior, allowing you to troubleshoot and fix issues more effectively.
I hope you find this guide helpful. Happy debugging!