JavaScript
The JavaScript node runs a JavaScript script as a step in a workflow, with variables you map in as JSON.
Screenshot placeholder
The palette describes it as "Run JavaScript". The node card tags it "Node.js".
When to use it
Use it when you need a custom calculation or data change written in JavaScript. If you want to choose the language on the node, or use TypeScript, use the Code node.
Settings
| Field | What it does | Notes |
|---|---|---|
| JavaScript code | Your script | Hint "Write your script below" |
| Input mapping (JSON) | The variables made available to the script | Hint "Variables available in script". Default {} |
| Output key | The name the result is stored under | Default script_output in the form. A new node starts with js_output |
A new node starts with this code:
async function run(input) {
// Your logic here
return { result: input };
}
Inputs and outputs
| Handle | Where | Purpose |
|---|---|---|
| Input | Top | The step that comes before |
| Output | Bottom | Continues the workflow with the script's result |
Example
This is an illustrative example. You want to tidy up a customer name.
- In Input mapping (JSON), map the name from the previous step into a variable.
- In JavaScript code, trim and format the name and return it.
- Read the cleaned name in the next step using the Output key.
Tips
- Keep the function name
run, as in the starter code. - Make sure Input mapping (JSON) is valid JSON.
- Use the Code node if you need to install npm packages from the settings panel.