Creating a function node
- Drag a Function node onto your decision graph
- Connect it between other nodes
- Click Edit Function to open the code editor
Basic structure
Every function node exports a handler that receives input and returns output:input parameter contains data from the previous node in your graph.
Accessing previous nodes
Useinput.$nodes to access outputs from any upstream node in your graph:
input.$nodes.NodeName.field to reference any field from an upstream node’s output. Node names are case-sensitive and must match exactly.
Example: Calculate loyalty points
Supported libraries
Function nodes include several built-in libraries:| Library | Purpose | Example |
|---|---|---|
dayjs | Date and time manipulation | dayjs().add(7, 'days') |
big.js | Arbitrary-precision decimals | new Big('0.1').plus('0.2') |
zod | Input validation and parsing | z.string().email().parse(input) |
http | HTTP requests (axios-like API) | await http.get(url) |
zen | Evaluate other decisions | await zen.evaluate(decisionId, input) |
Using dayjs
Using big.js for precision
Making HTTP requests
Async/await
Function nodes support async operations. Useasync/await for any asynchronous logic:
Debugging
Useconsole.log to debug your functions. Output appears in the simulator:
Execution limits
Function nodes have these constraints:| Limit | Value |
|---|---|
| Execution timeout | 5000ms (by default) |
| Memory | Shared with engine |