Run a small JavaScript snippet with a pinned Node.js runtime from a Dagu workflow.
This action is useful for lightweight JSON transforms, release metadata generation, conditional glue code, and other cases where a full checked-in script would be heavier than the logic itself.
steps:
- id: compute
action: node-script@v1
with:
input:
version: "1.2.3"
services: ["api", "worker"]
script: |
console.log("preparing release", input.version)
return {
tag: `v${input.version}`,
serviceCount: input.services.length,
services: input.services
}
- id: print
depends: [compute]
run: echo "release tag is ${compute.outputs.result.tag}"The action owns its runtime dependency:
tools:
- nodejs/node@v22.21.1Callers do not need to install Node on every worker image. Dagu prepares the pinned Node tool for the action DAG on the worker that runs it.
| Field | Required | Description |
|---|---|---|
script |
Yes | JavaScript function body. Use return to publish a result. await is supported. |
input |
No | JSON-compatible value available to the script as input. Defaults to null. |
env |
No | Object of string environment variables to add to process.env for the script. Also available as env. |
timeoutSeconds |
No | Async timeout enforced by the wrapper. Defaults to 30, max 300. CPU-bound infinite loops are still bounded by the action DAG step timeout. |
The script runs as an async function body with these variables in scope:
input // value from with.input, or null
params // full action input object
env // process.env plus with.env values
console // captured consoleDynamic imports work in the Node runtime:
steps:
- id: inspect
action: node-script@v1
with:
script: |
const os = await import("node:os")
return {
platform: os.platform(),
arch: os.arch()
}| Field | Description |
|---|---|
ok |
true when the script completed successfully. |
result |
JSON-compatible value returned by the script. undefined becomes null. |
stdout |
Text written with console.log, console.info, console.debug, or console.dir. |
stderr |
Text written with console.warn or console.error. |
durationMs |
Runtime duration in milliseconds. |
nodeVersion |
Node.js version used by the action. |
error |
Error object with name, message, and stack when the script fails. |
console output is captured for structured outputs and mirrored to the action step stderr so it remains visible in logs without corrupting the JSON stdout Dagu uses for outputs.
This action is not a sandbox. The script runs with the same permissions, filesystem access, network access, and secrets available to the Dagu worker process. Only run trusted JavaScript.
dagu-action.yaml
workflow.yaml
scripts/
run-node-script.mjs