Run TypeScript

action_run_ts · action · Utility · Available · v1.0.0

Description

Execute TypeScript code in the in-process isolated-vm sandbox (the same battle-tested engine as Run JavaScript: V8-level isolation, no filesystem/network/module access, memory cap and wall-clock timeout enforced by the isolate). TypeScript is transpiled with type-stripping only (no runtime type-check → <50ms compile latency even on 50KB scripts), so type annotations, interfaces, type aliases, enums and "as" casts are supported and simply vanish at runtime. Script globals: `input` (previous node JSON output), `vars` (persistent workflow variables), `ctx` (tenantId, runId, nodeId). The value you `return` becomes the node output (must be JSON-serializable). Use case: typed data transformations, typed business logic (tiered commissions, multi-field validation), input reshaping before an API call, proprietary customer algorithms written in TS. For CPU-heavy or scientific work use Run Python; for HTTP calls use HTTP Request.

⚙️ Configuration parameters

Fields shown in the editor when configuring the node. Generated directly from the NodeDefconfigFields.

FieldTypeRequiredDefaultDescription
code
Codice TypeScript
codeyes// input = output del nodo precedente // vars = workflow variables · ctx = { tenantId, runId, nodeId } interface Item { amount?: number } const items: Item[] = (input.items as Item[]) ?? []; const total: number = items.reduce((s, x) => s + (x.amount ?? 0), 0); return { total, count: items.length }; Codice TypeScript. Usa "return <value>" per emettere output (JSON-serializable). I tipi vengono strippati a runtime (no type-check). Strict mode. No require/import/fetch/process/eval. Per pattern data-transformation n8n-compat usa logic_transform.
timeoutMs
Timeout (ms)
numberno5000Tempo massimo esecuzione. Min 100, max 30000. Default 5s.
memoryLimitMb
Memory limit (MB)
numberno128Limite memoria isolated-vm. Min 16, max 512. Default 128MB.

💡 Configuration example

JSON snippet of the node as it appears in the workflow. Values are derived fromdefaultValue and from required parameters.

{
  "id": "node-action_run_ts-1",
  "defId": "action_run_ts",
  "label": "Run TypeScript",
  "config": {
    "code": "// input = output del nodo precedente\n// vars = workflow variables · ctx = { tenantId, runId, nodeId }\n\ninterface Item { amount?: number }\nconst items: Item[] = (input.items as Item[]) ?? [];\nconst total: number = items.reduce((s, x) => s + (x.amount ?? 0), 0);\nreturn { total, count: items.length };\n",
    "timeoutMs": 5000,
    "memoryLimitMb": 128
  }
}

🔗 Related nodes in the same category

Ready to use Run TypeScript?

Available now on all FlowForge plans. Try it free without a credit card.

Start freeBrowse all nodes