Skip to content

JavaScript

The JavaScript operation allows users to write custom logic in JavaScript, leveraging the lightweight QuickJS-ng runtime. It supports dynamic scripting through an Init Script (executed once upon component creation) and a Run Script (executed every time the component is reached in an active execution path), enabling flexible data processing and flow control.

JavaScript operation

Inputs

PortTypeRequiredDescription
In [1—20]User-configurableNoFlexible inputs that pass data into the JavaScript environment. Each value is accessible via getInput(inputNumber). Up to 20 connectable inputs. Accepted MessagePack types per port are set in the Node’s Settings panel — see Setting Port Types.

Outputs

PortTypeDefaultDescription
Out [1—20]User-configurableNilFlexible outputs set from the script via setOutput(outputNumber, value). Up to 20 connectable outputs. Accepted MessagePack types per port are set in the Node’s Settings panel.

Properties

NameTypeDefaultDescription
InitTextBox (multi-line)""JavaScript code executed once when the component is created. Use var for variables shared with the Run script.
RunTextBox (multi-line)""JavaScript code executed every time the component is reached in an active execution path.
On ErrorComboStop this branchPer-op On Error verb (Stop this branch / Continue with the last value / Continue with the fallback). See the Error Handling guide.

State on Reload

State is preserved across restarts within the configured time window. The current outputs and the global state value (if present) are saved. State is restored only if the Init and Run scripts are unchanged (script hash match). The saved state is applied after the Init Script has run.


The following global functions are available in both the Init and Run scripts:

FunctionDescription
getInput(inputNumber)Returns the decoded native JavaScript value of the given 1-based input. Unconnected or invalid inputs return undefined; MessagePack Nil becomes null. Maps with only string keys become plain objects; others become Map.
setOutput(outputNumber, value)Sets an output using a native JavaScript value. Array/Object/Map are converted recursively; Uint8Array/ArrayBuffer becomes binary; null, undefined, and unsupported types become Nil. BigInt is supported up to 64-bit range.
pathHalt(shouldHalt)Controls whether the execution path stops after this operation. Pass true to stop, false (or omit the call) to continue. See Error Handling below.
console.log(...args)Logs messages to the system Statuses table for debugging.

  1. Initialization — When the component is first created, deployed, or reloaded, the Init script is executed once. Variables declared with var or function are available in the Run script.

  2. Runtime execution — Each time the component is reached in an active execution path, the Run script is processed.

  3. Input handling — Within the Run script, getInput(inputNumber) returns decoded native JavaScript values from the MessagePack inputs.

  4. Custom logic — The script processes values, performs calculations, applies conditional logic, or manipulates data as needed.

  5. Output handling — Results are set using setOutput(outputNumber, value). Conversion to MessagePack is handled automatically.

  6. Path control — pathHalt(true) can be called to stop the execution path based on conditions within the script. If not called or called with false, the path continues.


Purpose: Pass data from a single input directly to a single output.

Run Script:

let input1 = getInput(1);
setOutput(1, input1);

Input 1: "Some data"

Output 1: "Some data"


  • The QuickJS-ng runtime is sandboxed. Browser APIs (DOM, setTimeout) and Node.js modules are not available.
  • Execution is synchronous — avoid infinite loops or heavy computation that could block the workflow.
  • Variables declared with let or const in the Init script are block-scoped and may not be accessible in the Run script. Use var for shared globals.
  • Integers outside JavaScript’s safe range are represented as BigInt when read. BigInt values are accepted on output if they fit in 64-bit range.
  • MessagePack Extension values are returned as undefined.
  • If the Run script throws, the Node fails and its On Error verb resolves the branch; outputs the script already wrote are not cleared.

JavaScript carries an On Error verb like every other operation. What the script does is what decides which of the three answers a run gives:

What the script doesThe run’s answer
Calls setOutput and returnsProduced. Every output the script set is written and stamped with this run, and the dependents run.
Calls pathHalt(true)Stopped. The outputs are untouched and the dependents are skipped. This is a choice, not an error, so no verb is consulted.
Throws, and nothing catches itFailed. The error is reported as JavaScript: run script failed, and the On Error verb below resolves the branch.

An uncaught throw is the script’s one way to say it could not produce. Outputs the script wrote before it threw keep the values and the stamps it gave them.

VerbWhat a dependent gets
Stop this branch (default)This Node and its dependents stop; every output keeps its value and reads as a failed update.
Continue with the last valueDependents run on the value each output already holds, not stamped as new; it reads as a failed update.
Continue with the fallbackDependents run on each output’s per-output Fallback, stamped as this run’s value; it reads as a failed update. The Editor refuses a Task where a Fallback is unset.

A Node that failed is also what a downstream Input configured with A value whose last update failed reads on its next fire, whichever verb the Node carries.

Wrap risky code in try/catch to decide for yourself which failures are worth failing the Node over.