> For the complete documentation index, see [llms.txt](https://docs.digibee.com/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.digibee.com/documentation/connectors-and-triggers/connectors/tools/script.md).

# Script (JavaScript)

Discover more about the Script (JavaScript) connector and how to use it on the Digibee Integration Platform.

**Script** **(JavaScript)** allows the execution of JavaScript code excerpts (JavaScript is also known as ECMAScript).

## Parameters

Configure the connector using the parameters below. Fields that support [Double Braces expressions](/documentation/connectors-and-triggers/double-braces/overview.md) are marked in the **Supports DB** column.

| Parameter              | Description                                                                                                        | Type    | Supports DB | Default |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------ | ------- | ----------- | ------- |
| **Code**               | Place to insert the JavaScript code.                                                                               | String  | ❌           | N/A     |
| **Script Timeout**     | Maximum time (in milliseconds) the script is allowed to run. **The timeout cannot exceed 300,000 ms (5 minutes).** | Integer | ❌           | N/A     |
| **Use Legacy Runtime** | Runs the script on the previous runtime. Enable only if a script behaves differently on the default runtime.       | Boolean | ❌           | `false` |

{% hint style="info" %}
Pipelines that used **Use Experimental Runtime** need no changes. That option was removed when the new runtime became the default.
{% endhint %}

## Messages flow

### Input

The **Script** **(JavaScript)** connector can receive former connector parameters from the `"body"` object. In other words, if the connector that comes before **Script** **(JavaScript)** has an output that includes an object called `"body"`, it's possible to access it directly in the **Script** **(JavaScript)** code.

* **body:** object imported to the **Script** **(JavaScript)** code scope.

For example, if the input is:

```json
{
   "body": {
       "company": "Digibee"
   }
}
```

Then it will be possible to use the **Code** field to do something like this:

```javascript
var x = body.company;
```

### Output

The code executed in the connector can produce an output, as long as it's assigned to the global variable named output.

* **success:** `"true"` if the code execution was successful; otherwise `"false"`.
* **output:** custom output of the connector.

For example, if you want the **Script (JavaScript)** connector output to be `'Hello world'`, assign it to the output variable:

```javascript
output = 'Hello world';
```

The result after the pipeline execution will be:

```json
{
   "success": true,
   "output": "Hello world"
}
```

It's also possible to build a JSON object as an output:

```javascript
output = { "company": "Digibee" }
```

The result after the pipeline execution will be:

```json
{
   "success": true,
   "output": {
       "company": "Digibee"
   }
}
```

If an error occurs during the script execution, the following output is displayed after the pipeline execution:

```json
{
   "success": false,
   "error": "Error message"
}
```

{% hint style="warning" %}
For security reasons, it's not possible to execute a function that makes an external call from the **Script (JavaScript)** connector, such as `fetch()` or `XMLHttpRequest()`. It's also not possible to import libraries with `require`.
{% endhint %}

The following libraries are already available and can be used:

* Lodash (global variable to use lodash lib: 'lodash')
* Moment Timezone (global variable to use moment-timezone: 'moment')

## **Usage guidelines**

### **Characteristics of the connector**

By default, the **Script (JavaScript)** connector runs your code inside the pipeline. The script uses the pipeline's own memory and CPU, so heavy scripts count against the pipeline size. Keep this in mind when choosing the pipeline size, and follow the [performance and resource usage tips](#performance-and-resource-usage-tips).

If you enable **Use Legacy Runtime**, the script runs on the previous runtime, which has its own infrastructure located outside the pipeline. This infrastructure is shared across the entire platform cluster. For this reason, it's important to use it consciously and moderately to avoid bottlenecks between pipelines that rely on it.

{% hint style="info" %}
The increase in resource capacity of this infrastructure is monitored and managed by the Digibee Integration Platform infrastructure team.
{% endhint %}

### **Recommendations and best practices**

The **Script (JavaScript)** connector is commonly used for data transformation and decision tree implementation, due to its versatility.

However, whenever possible, the Digibee Integration Platform recommends using optimized, pipeline-embedded connectors for data transformation and mapping — such as [**JOLT**](/documentation/connectors-and-triggers/connectors/tools/jolt-v2.md), [**JSLT**](/documentation/connectors-and-triggers/connectors/tools/jslt.md), [**JSON Transformer**](/documentation/connectors-and-triggers/connectors/tools/json-transformer.md), and [**JSON Generator**](/documentation/connectors-and-triggers/connectors/tools/json-generator.md). This reduces the risk of processing bottlenecks that can occur with **Script (JavaScript)**.

Use the **Script (JavaScript)** connector primarily in cases where JavaScript is the only viable option.

### **Performance and resource usage tips**

To ensure stable and efficient execution, follow these best practices and avoid common causes of CPU/memory overload:

* **Limit input sizes per execution**: Avoid processing very large datasets in a single run.
* **Prefer iterative approaches**: Use loops instead of recursion if recursion depth could grow significantly.
* **Avoid deep cloning in hot paths**: Use shallow copies or structural sharing when possible to reduce memory usage.
* **Use efficient Lodash operations**: Prefer `_.forEach` or `_.map` with simple iterators; avoid unnecessary `_.chain` on large datasets.
* **Validate date/time logic**: Handle timezone edge cases carefully; prefer UTC when possible.
* **Avoid heavy computations or unbounded loops**: Infinite/long loops, large nested iterations, or deep recursion without base cases can overload the engine.
* **Be careful with JSON and regex**: Repeated parsing/stringifying of large JSON objects or heavy regex operations on big strings can impact performance.
* **Monitor object creation**: Excessive cloning, merging, or creation of temporary objects in hot loops increases memory usage.
* **Manage large inputs/outputs**: Very large JSON payloads may exceed memory limits or trigger long garbage collection pauses.

Following these recommendations helps reduce the risk of pipeline interruptions, improves performance, and ensures the **Script (JavaScript)** connector runs efficiently.<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.digibee.com/documentation/connectors-and-triggers/connectors/tools/script.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
