Skip to content

Code

The Code operation runs a short JavaScript, much like the Code node in n8n. The script reads the results of the trigger and the actions before it, reshapes them and returns an object that the next actions use like any other result: {{Name.Response.key}}.

Typical cases: adding up amounts, filtering or sorting a list, splitting and joining text, converting dates, bringing an API’s answer into the shape the next API expects. Placeholders are not enough for this, since they don’t calculate.

In the visual editor you find Code under Logic. Its form has a field for the code and one for the time limit. Drag a value from the test view into the code and it becomes the matching JavaScript path, e.g. data.LoadCustomer.Response.Body.name. Test step shows the result right away.

{
"Type": "Code",
"Name": "Total",
"Parameters": {
"Code": "const items = input.Response.Body.items;\nreturn { count: items.length };",
"TimeoutSeconds": 30
}
}
Parameter Default Meaning
Code – The JavaScript. It is the body of a function: what it gives back with return is the result.
TimeoutSeconds 30 After this many seconds the script is stopped and the action fails; 0 = no limit.
Name Content
input The result of the action that finished just before, e.g. input.Response.Body. In the first action, the trigger’s result. After an If, Loop or Parallel, its own result.
data Everything the run knows so far, under the same paths as in {{…}}: data.InitialData, data.Trigger, data.FilePath, data.FileName, data.FileContent, in a Loop data.item and data.index, in OnError data.Error, and every action under its name: data.LoadCustomer.Response…
console.log(…) Writes a line to the log (console.warn as a warning, console.error as an error); objects appear as JSON.

The data arrives as plain JavaScript values: objects, lists, text, numbers, true/false. Dates are text in the form 2026-11-04T08:30:00; new Date(…) turns them into a date.

When the script returns an object, it is the action’s Response:

return { count: 3, total: "1234.50" };
"Response": { "count": 3, "total": "1234.50" }

The next actions read it as {{Total.Response.count}}. Any other value (text, number, list) is in Response.Result, so a list is at {{Total.Response.Result}}, for example as the Items of a Loop. Without return, Response is empty.

Meta.Logs holds the output of console.log (at most 200 lines; all of them are in the log), Meta.DurationSeconds the run time.

  • JavaScript up to ES2023: const/let, arrow functions, template strings with `${…}`, destructuring, ?. and ??, map/filter/reduce, JSON, Math, Date, regular expressions.
  • The script runs inside RUNOS, without access to files, network, programs or Windows. There is no require, import, fetch or setTimeout. For files, mails and APIs use the actions before or after it.
  • Errors: when the script throws an error (throw new Error("No customer found")) or has a typo, the action fails with the message and the line, e.g. Line 3: No customer found. The error policy then applies as for any action.
  • An endless loop ends after TimeoutSeconds, too deep recursion (over 1000 nested calls) with an error message. Stopping the workflow stops the script too.

An HTTP request LoadInvoices returns a list; Code picks the open ones and calculates:

const items = data.LoadInvoices.Response.Body.items;
const open = items.filter(r => r.status === "open");
console.log(`${open.length} of ${items.length} open`);
return {
count: open.length,
total: open.reduce((s, r) => s + r.amount, 0).toFixed(2),
numbers: open.map(r => r.number).join(", ")
};

A mail after it writes: {{Total.Response.count}} open invoices, {{Total.Response.total}} €: {{Total.Response.numbers}}.

With the File trigger and files like 10042_RE-2026-117.pdf:

const [customer, number] = data.FileName.replace(/\.pdf$/i, "").split("_");
if (!number) throw new Error("File name without invoice number: " + data.FileName);
return { customer, number, year: number.split("-")[1] };
return input.Response.Body.contacts
.filter(c => c.email)
.map(c => ({ name: `${c.firstName} ${c.lastName}`, email: c.email.toLowerCase() }));

The list is in {{Contacts.Response.Result}}; a Loop with these Items sends one mail per contact to {{item.email}}.