---
title: JavaScript Code
description: Transform items with a few lines of JavaScript, in a sandbox with no network
---

Write a small JavaScript transform when no other step does what you need. It starts fast and runs in a sandbox: no network, no page access, no timers.

## What it does

JavaScript Code runs your code in QuickJS, a small JavaScript engine compiled to WebAssembly, inside its own worker for each run of the step. The engine loads the first time the step runs.

At the top of **Setup**, a green card says what the step can reach: **What it touches: nothing outside this step**. No internet (use [HTTP Request](/nodes/builtin/core/http-request/) for calls), no web pages, tabs or your files, no connections or stored data, and how long it may run (*Stops after …*), with **Change limits** (the step's **Time limit**). In **Ready to run** and on a Marketplace listing, the step shows as a calm grey *Runs code in a sandbox* row, not a warning.

Pick how it runs with **Run**:

* **Once for each item** (the default): `item` is the current item and `$itemIndex` its position (from 0). Return the new item. Each item gets a fresh engine, so nothing leaks from one item to the next.
* **Once for all items**: `items` is the whole list. Return the new list; each element becomes one item.

Both modes also get `$workflow` (`id`, `name`) and `$execution` (`id`, `mode`). The data you read is frozen JSON: change a copy (`{ ...item }`), not the original. Async code works: a returned promise is awaited.

What comes out:

* An object is the item. Any other value becomes `{ result: value }`. Returning nothing gives an empty item.
* In **Once for all items**, the code must return a list, or the step fails with `"Once for all items" code must return a list`.

`console.log()` lines go to the run's activity log (the first 200; after that, one line says the rest are hidden). `console.warn()` and `console.error()` show as warnings and errors.

:::note\[`{{ }}` is not replaced in code]
The code field is sent to the engine exactly as you wrote it. Read data with `item` or `items`, never with `{{ $input.x }}`.
:::

## When to use it

* A calculation or a reshaping that would take several steps otherwise.
* Filtering or sorting with a rule that is easier to write than to click.
* When you know JavaScript better than Python. [Python Code](/nodes/builtin/core/code/) does the same job in Python, but starts slower.

For counts, sums and averages per group, try [Summarize items](/nodes/builtin/datatransformation/summarize/) first: no code needed.

## Inputs and settings

```js title="Once for each item"
// item is the current item; return the new one
return { ...item, total: item.qty * item.price };
```

```js title="Once for all items"
// items is every item; return the new list
return items.filter((i) => i.active).map((i) => ({ name: i.name }));
```

Limits:

* **Time limit**: 10 seconds by default, up to 60 seconds. A run that goes over stops with `Stopped after 10 s (time limit).`
* **Memory limit**: 64 MB by default, up to 256 MB. Going over stops with `Used more than 64 MB (memory limit).`
* **Stop** in the app ends the code at once.

## Outputs

The items your code returned, one per object.

## Dependencies and credentials

None. This node needs no connection and has no slots for other nodes.

The sandbox has no `fetch`, `XMLHttpRequest`, `WebSocket`, timers or imports. To call an API, put an [HTTP Request](/nodes/builtin/core/http-request/) step before or after this one.

## Example workflow

1. [HTTP Request](/nodes/builtin/core/http-request/) fetches a list of orders (one item per order).
2. JavaScript Code, **Once for each item**: `return { ...item, total: item.qty * item.price };`
3. [Summarize items](/nodes/builtin/datatransformation/summarize/) sums `total` per `region`.

## Common issues

* **`Line 3, item 2: TypeError: …`**: the error names the line of your code and the item (counted from 1). Open the step's Input to see that item.
* **`'fetch' is not defined`**: the sandbox has no network. Use HTTP Request for calls.
* **The output still shows `{{ … }}`**: expressions are not replaced in code. Read the value from `item`.
* **"Once for all items" fails**: return a list, for example `return items;`.

## Related nodes

* [Python Code](/nodes/builtin/core/code/): the same idea in Python.
* [Summarize items](/nodes/builtin/datatransformation/summarize/): totals and counts per group, no code.
* [Edit Fields](/nodes/builtin/datatransformation/editfields/): add, rename or set fields without code.