> For the complete documentation index, see [llms.txt](https://docs.stacksync.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stacksync.com/agentic-workflows/features/code-execution/javascript-code-execution.md).

# Javascript Code Execution

Run custom JavaScript scripts directly inside your workflow. Use it for fast data formatting, string manipulation, date operations, or lightweight logic between nodes.

### 1. Add the Module

Add the **JavaScript Code** module to your workflow as an action node.

<figure><img src="https://3389950191-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO4RFXIz4V8iqghJ3JVSs%2Fuploads%2FcusnKQH9H4Tb8QKAusa6%2Fimage.png?alt=media&amp;token=03b64b15-38c3-41fe-97bb-bce626527541" alt=""><figcaption></figcaption></figure>

### 2. Pass Data In Context

In the module configuration panel, add context variables under the **Context** section. Each entry takes a **Name** and a **Value** use the variable picker to map values from upstream nodes.

<figure><img src="https://3389950191-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO4RFXIz4V8iqghJ3JVSs%2Fuploads%2FLq5N1345VBiLa7Vham81%2Fimage.png?alt=media&amp;token=097ef82c-e2d7-47f1-92ad-7ca9a5f47fe7" alt=""><figcaption></figcaption></figure>

Each context entry becomes a key on `WORKFLOW_CONTEXT` inside your script:

```javascript
function main(WORKFLOW_CONTEXT) {
    const amount = WORKFLOW_CONTEXT.amount;
    const currency = WORKFLOW_CONTEXT.currency;
}
```

### 3. Write Your Script

Your script must define a `main` function. Stacksync automatically injects `WORKFLOW_CONTEXT` as the argument containing all your context values.

```javascript
function main(WORKFLOW_CONTEXT) {
    const amount = WORKFLOW_CONTEXT.amount;
    const currency = WORKFLOW_CONTEXT.currency;
    return {
        amount: amount,
        currency: currency
    };
}
```

### 4. Return Data

Whatever `main` returns becomes the node's output, available to downstream nodes via standard node referencing.

<figure><img src="https://3389950191-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO4RFXIz4V8iqghJ3JVSs%2Fuploads%2Fmyu3k8vbmJufA9vEKrGw%2Fimage.png?alt=media&amp;token=8b633118-4067-42a0-9e1f-09f01cf9c155" alt=""><figcaption></figcaption></figure>

Reference in downstream nodes:

```
{{ your_module_id.amount }}
{{ your_module_id.currency }}
```

> **Debugging:** `console.log()` output is captured and surfaced under `metadata.stdout` in the execution logs. Use it for debugging, it does not pass data downstream.

### Available Libraries

| Library                     | Use case                    |
| --------------------------- | --------------------------- |
| `dayjs`                     | Date parsing and formatting |
| `moment`                    | Date manipulation           |
| `live-plugin-manager`       | Dynamic module loading      |
| Node.js 23 standard library | All built-in modules        |

> **Note:** You cannot install additional packages at runtime with `npm install`.&#x20;

### Limits

| Limit            | Value                |
| ---------------- | -------------------- |
| Timeout          | 6s                   |
| Memory           | 8 GB                 |
| Filesystem       | Read-only, no writes |
| Runtime packages | Pre-installed only   |

> **Watch out:** Avoid using JavaScript for slow HTTP calls, heavy loops, or large dataset operations as the timeout is 6 seconds, use the Python Code module instead.
