
JavaScript node
JavaScript Node
Overview
The JavaScript Node executes custom JavaScript against the pipeline payload and returns the result on a single result output port. It is ideal for ad-hoc transformations, quick calculations, and bridging logic gaps when purpose-built nodes are unavailable. The node injects pipeline context variables, runs the user script inside the Maestro engine, and wraps the return value in a consistent structure for downstream nodes.
Core Functionality
1. Inline JavaScript Execution
- Author arbitrary ES5/ES6-compatible JavaScript directly inside the node.
- Access pipeline context variables such as
$input,$inputs,$node, and more. - Return any JSON-serializable value (objects, arrays, scalars) via a
returnstatement.
2. Context Injection
$input: The primary payload (single input or merged data).$inputs['PortOrNode']: Map of inbound packets when synchronizing multiple sources.$node: Metadata describing the current node (id, type, label).- Additional globals (
$pipeline,$execution) are exposed via the expression service for advanced scenarios.
3. Auto-Wrapped Output
- Result is emitted through
defaultOutunder theresultfield. - Downstream nodes receive payloads shaped as
{ "result": <return value> }. - Access outputs via
$input.resultor drill into nested fields such as$input.result.customer.
4. Standard Settings
- Shares baseline retry and error handling controls with other nodes.
- Documentation settings let you annotate the purpose of the script on the pipeline canvas.
Configuration Reference
Parameters Configuration
Settings Configuration
Parameters (Dynamic Data)
| Field | Type | Default | Description |
|---|---|---|---|
| Javascript Code | string | "" | Required JavaScript snippet that must include a return statement. |
| Debug Mode | boolean | false | Enables verbose execution logging. |
Settings (Static Configuration)
| Field | Type | Default | Description |
|---|---|---|---|
| Retry on Fail | boolean | false | Retries execution when infrastructure issues interrupt the script. |
| On Error | string | "Stop Pipeline" | "Stop Pipeline" fails the branch, "Continue Execution" forwards an error payload, "Retry Node" replays the script under retry policies. |
| Notes | string | "" | Document the script’s intent for collaborators. |
| Display Note in Pipeline | boolean | false | Shows the note directly on the canvas. |
Usage Examples
Example 1: Format Operator Summary
| Field | Value |
|---|---|
| Script | See snippet below |
| Notes | Build operator display name for dashboards. |
| Display Note in Pipeline | true |
const operator = $input.operator;
return {
id: operator.badgeId,
name: `${operator.firstName} ${operator.lastName}`.trim(),
activeShift: operator.shift
};
The downstream payload exposes the formatted object under $input.result.
Example 2: Calculate Production Yield
| Field | Value |
|---|---|
| Script | See snippet below |
| On Error | Continue Execution |
const produced = Number($input.goodUnits || 0);
const defective = Number($input.scrapUnits || 0);
const total = produced + defective;
if (!total) {
return { yield: 0 };
}
return { yield: Number(((produced / total) * 100).toFixed(2)) };
Even if the script throws, the Continue Execution setting lets the branch proceed for monitoring.
Example 3: Summarize Packaging Batch Metrics
| Field | Value |
|---|---|
| Script | See snippet below |
| On Error | retryNode |
| Notes | Create aggregated stats for the current packaging batch. |
const cartons = Array.isArray($input.cartons) ? $input.cartons : [];
const totalWeight = cartons.reduce((sum, carton) => sum + (carton.weightKg || 0), 0);
const defectiveCount = cartons.filter(carton => carton.defectFlag === true).length;
return {
batchId: $input.batchId,
cartonCount: cartons.length,
averageWeightKg: cartons.length ? Number((totalWeight / cartons.length).toFixed(2)) : 0,
defectiveCount
};
Use this when a packaging station sends per-carton details and you need a single summary object for downstream reporting.

