# JavaScript

Source: https://openflow.run/en/docs/nodes/code/
Language: en
Product version: 0.1.0-beta.77

Transform inputs with an isolated JavaScript module and explicitly declared outputs.

Use the JavaScript node for transformations, calculations, or combining supported capability calls. For a single HTTP request without transformation, HTTP Request usually needs less configuration.

## Module and ports

Code is an ES module whose default export receives `(inputs, context)` and returns business outputs, or a Promise of those outputs.

```javascript
export default ({ name, prefix }) => ({
  message: `${prefix}, ${name}!`
});
```

Declare custom output schemas through `config.outputs`. Bind named inputs directly, with optional constraints in `config.inputs`. The public interface owns module identities and runtime assembly.

```json
{
  "op": "node.add", "as": "greet", "type": "code", "name": "Compose greeting",
  "code": "export default ({name, prefix}) => ({message: `${prefix}, ${name}!`});",
  "config": { "outputs": { "message": { "schema": { "type": "string" }, "nullable": false } } },
  "inputs": {
    "name": { "kind": "value", "value": "Ada" },
    "prefix": { "kind": "value", "value": "Hello" }
  }
}
```

Start supplies a name, Value supplies a prefix, Code combines them, and Outputs declares the workflow result.

**Input**
{"name":"Ada"}

**Expected result**
{"message":"Hello, Ada!"}

**Before running**
An Open Flow deployment is needed to execute or import this example. The preview itself runs offline.

[Download workflow](https://openflow.run/docs/examples/first-workflow.openflow.json)

## Runtime boundaries

The supported Node built-ins form a compatibility subset. A fresh in-memory filesystem starts at `/tmp` for each Task. It does not expose the host disk or persist into the next invocation. Arbitrary packages, dynamic imports, and CommonJS `require` are unavailable.

Use explicit Code capabilities for Connector Actions, workflow calls, and HTTP hosts. `context.fetch` is bounded by the declared hosts and the deployment’s current Engine Contract. It does not inherit platform credentials or grant unrestricted networking.

## Persistent results and failures

Return JSON business outputs. Use the supported Artifact interface for Run-owned bytes, and explicit [Flow State](https://openflow.run/en/docs/concepts/flow-state/index.md) for cross-Run business values. Virtual files and local globals are not durable stores.

Code supports [Task retries and handled errors](https://openflow.run/en/docs/concepts/errors-and-retries/index.md). A retry repeats the whole module and can repeat external operations. Resource limits, cancellation, and unknown outcomes retain their runtime boundaries.

## Sources

*   [docs/authoring/node-authoring.md](https://github.com/oomol-lab/open-flow/blob/e25a738d170322734572a0b8a1323cb00b9d355a/docs/authoring/node-authoring.md)
*   [docs/control/contracts/nodejs-runtime.md](https://github.com/oomol-lab/open-flow/blob/e25a738d170322734572a0b8a1323cb00b9d355a/docs/control/contracts/nodejs-runtime.md)
*   [docs/control/contracts/control-api.md](https://github.com/oomol-lab/open-flow/blob/e25a738d170322734572a0b8a1323cb00b9d355a/docs/control/contracts/control-api.md#10-code-action-contract)
*   [packages/open-flow/src/workbench/browser/runtime/editor/addNodeOptions.ts](https://github.com/oomol-lab/open-flow/blob/e25a738d170322734572a0b8a1323cb00b9d355a/packages/open-flow/src/workbench/browser/runtime/editor/addNodeOptions.ts)
