Custom JS Function
The Custom JS Function node is a utility component that allows users to execute custom JavaScript functions within their workflows. This node provides flexibility and extensibility by enabling users to write and run their own JavaScript code as part of the data processing pipeline.
Node Details
-
Name: CustomFunction_Utilities
-
Label: Custom JS Function
-
Type: CustomFunction
-
Category: Utilities
-
Version: 3.0
Input Parameters
-
Input Variables (optional)
-
Type: JSON
-
Description: Input variables that can be used in the function with a ‘var)
-
Accepts variables and lists
-
-
Function Name (optional)
-
Type: String
-
Description: A name for the custom function
-
Placeholder: “My Function”
-
-
Additional Tools (optional)
-
Type: Tool
-
Description: Tools that can be used in the function with $tools.
.invoke(args)
-
Accepts a list of tools
-
-
Javascript Function
-
Type: Code
-
Description: The custom JavaScript function to be executed
-
Outputs
-
Output
-
Types: string, number, boolean, json, array
-
Description: The result of the custom function execution
-
-
Ending Node
-
Type: CustomFunction
-
Description: Indicates if this node is the final node in the workflow
-
Functionality
The Custom JS Function node creates a sandboxed environment to execute the provided JavaScript code. It offers the following capabilities:
-
Access to input variables, flow metadata, and custom tools
-
Ability to use both built-in Node.js modules and external dependencies (configurable via environment variables)
-
Secure execution using NodeVM to isolate the custom code
Usage
-
Define input variables (if needed) in JSON format
-
Optionally, provide a name for your function
-
Add any additional tools required by your function
-
Write your custom JavaScript function in the code editor
-
The function’s return value will be passed as the output to the next node in the workflow
Security Considerations
-
The node uses NodeVM to create a sandboxed environment, limiting access to the host system
-
Built-in dependencies and external modules can be configured using environment variables:
-
TOOL_FUNCTION_BUILTIN_DEP: Comma-separated list of additional built-in modules to allow
-
TOOL_FUNCTION_EXTERNAL_DEP: Comma-separated list of additional external modules to allow
-
Example
This node is particularly useful for implementing custom logic, data transformations, or integrating external services that are not covered by other nodes in the system.