InitfinityTM
Initfinity / Docs / Code, WebAssembly and Script Nodes

Code, WebAssembly and Script Nodes

When the built-in nodes are not enough, drop into code. The Code node runs JavaScript or Python, the WASM node runs WebAssembly modules, and the Script Runner and Script Eval nodes run terminal commands.

Code Node

The Code node runs your own code as one step of a flow. Pick the language in the node's Language field.

Code runs in a pool of web workers, so heavy work does not freeze the canvas.

Inputs and outputs

Whatever arrives on the node's In port is available as inputs.in. To send data downstream, return an object with an out key:

const nums = inputs.in ?? [];
const total = nums.reduce((a, b) => a + b, 0);

return { out: { total, average: total / nums.length } };

You can also assign the object to a variable named result instead of returning it. In Python, assign to result:

nums = inputs.get("in", [])
total = sum(nums)

result = {"out": {"total": total, "average": total / len(nums)}}

Python inputs arrive as plain dictionaries and lists, and the returned dictionary is converted back to JSON-like data.

JavaScript

  • Your code runs inside an async function, so you can use await.
  • Standard built-ins are available: Math, JSON, Date, Map, Set, RegExp, typed arrays, Intl, crypto, TextEncoder and WebAssembly.
  • fetch is available for network requests.
  • console.log, console.warn and console.error show up in the Debug Panel and the terminal.
  • toast(message), confetti(), prompt(message), confirm(message) and navigator.clipboard talk to the editor when you run in the browser.
  • ctx (also context, global and globalThis) is an object shared by every Code node during one run, handy for passing state between nodes.
  • math.evaluate("2 * (3 + 4)") evaluates a math expression.
  • The DOM, window, eval and Function are not available. Reaching for one throws a clear error.

Python

Python runs in your browser on Pyodide, a WebAssembly build of CPython. The first Python node in a session takes a moment to load the runtime; after that it is fast.

Packages

Fill the Dependencies field to use libraries. Enter one per line or separate them with commas.

  • Python: package or package==version, installed from PyPI with micropip. For example numpy or pandas==2.2.3. Packages must be pure Python or have a Pyodide build.
  • JavaScript: an npm package name such as lodash, or a full URL to a script. Packages are loaded from a CDN and expose their global (for example _ for lodash).

Dependencies are fetched on first use and reused for the rest of the session.

Run input text as code

By default, text arriving on In is data. Turn on Run input text as code to execute it instead. Use it only with input you trust. Hosting a flow is blocked when this node can be reached from a webhook or a credential.

WASM Node

The WASM node runs a WebAssembly module and returns the result.

  • Mode: plain WASM, a WASI program or a component.
  • Source: a URL, a Base64 string or a path in the virtual filesystem.
  • Export Name: the exported function to call, run by default.
  • Max Memory Pages: the memory limit for the module.

Script Runner and Script Eval

These two nodes run terminal commands, not JavaScript. A script is a list of commands, one per line, with # for line comments and /* */ for block comments.

# tune the editor, then run the flow
theme set mint
run
  • Script Runner reads a script file from the virtual filesystem (for example /scripts/my-script.script).
  • Script Eval runs the script text you give it.

Both output the number of commands executed and the list of commands. In the terminal, script <path> runs the same kind of file.

Terminal

Press Alt+S to open the dropdown terminal. It is a shell over the virtual filesystem, with commands for files (ls, cd, cat, edit, mkdir, cp, mv, zip), flows (run, stop, host, load, flob) and version control (git). Plugins can add their own commands.

Git

Your flows, notes, custom nodes and plugin data each live in their own git repository, created automatically the first time you save there. This powers version history in the File Explorer. Other files in the virtual filesystem are not tracked. You can also drive git from the terminal:

git status
git add .
git commit -m "tune the alert threshold"
git log
git branch feature
git checkout feature

Pair it with the text FDL format and flows diff cleanly in version control.

Best Practices

  • Keep each Code node focused on one job, and prefer built-in nodes (Math, String Transform, JSON Path) for common operations.
  • Use fetch in code for one-off calls, and the HTTP Fetch node when you want the request visible on the canvas.
  • Return an out object so downstream nodes get a predictable shape.
  • Pin Python packages with package==version for repeatable runs.
  • Avoid infinite loops and very large payloads; worker time and memory are limited.

Debugging

  1. Use console.log and Logger nodes to print intermediate values.
  2. Open the Debug Panel (Alt+D) for error messages and stack traces.
  3. Set a breakpoint on the node and step through with F10.

Sandbox

JavaScript runs in a restricted scope inside a worker. It cannot touch the page, the DOM or the main thread, and it only sees the globals listed above. Treat Code nodes in flows you import from others with the same care as any script, and read them before you run them.