Javascript
Execute custom Javascript code within your workflow to process data dynamically.
What is the Javascript Node?
The Javascript feature allows execution of custom Javascript code within a workflow. This capability enables input data to be processed using the provided script and outputs the resulting JSON object. It offers high flexibility and can be used for various data manipulation tasks, conditional logic, and more. It runs in a secure sandbox with limited APIs but provides logs to debug or analyze/track your script execution.
How to use it?
Follow these steps to set up and use Javascript:
-
Configure Script Source:
- Script Source:
- Choose between "Inline script" or "External script".
- Script:
- If using an inline script, enter your Javascript code directly in the provided text area.
- External Script:
- If using an external script, provide the URL or path to the script file.
- Script Source:
-
Write your Script:
- Your script result must return a JSON object or you will get errors. That can be any valid JSON object.
-
Access your input data:
- Your input JSON objet is accessible under a
inputvariable. It can be accessed as if it was created as a const, soconsole.log(input)shows the full input andconsole.log(input.property)will show the specific property of the object you provided.
- Your input JSON objet is accessible under a
-
Test:
- Run the graph and check the results. If something isn't working consider the debugging section below.
Available APIs
The JavaScript execution environment is a secure sandbox with limited APIs for security reasons:
Available
console- Logging methods:log(),warn(),error(),info(),debug()- Standard JavaScript - All built-in language features (async/await, promises, array methods, object methods, Math, Date, JSON, etc.)
NOT Available
- ❌ No Node.js APIs (no
require,import,process,Buffer) - ❌ No file system access
- ❌ No network access (no
fetch, no HTTP requests) - ❌ No timers (
setTimeout,setInterval) - ❌ No external libraries or npm packages
Example
// ✅ This works - using standard JavaScript
const result = input.items.map(item => ({
...item,
processed: true,
timestamp: new Date().toISOString()
}));
console.log('Processed items:', result.length);
return { processedItems: result };
Logs & Debugging
Use console.log(), console.warn(), console.error(), console.info(), or console.debug() to output debug information. All console output will appear in the logs tab of your graph execution.
Additional Information
When using Javascript with other features, ensure that the data types match the expected input and output types. This feature is highly flexible and can be used in various scenarios where custom logic needs to be applied to the workflow data. For more advanced scripting techniques and examples, refer to the Mozilla Developer Network (MDN) Javascript documentation.