viaSocket Help

Use JavaScript Code

JS Code steps let you run custom JavaScript inside your workflow — useful for data manipulation, calculations, conditional logic, or calling external APIs.


📌

JS Code runs as an action step. It executes after your trigger and can use data from any previous step as input.

#

When to Use JS Code

  • Perform calculations or transform data before passing it to the next step

  • Handle logic that built-in actions can't cover

  • Call external APIs and process the response

  • Filter, format, or restructure input data based on conditions

#

How to Add a JS Code Step

#

1. Add a JS Code action

In the workflow editor, click + Add Step. In the panel that opens, scroll to Built-In Tools and select JS Code.

jscode1.png
#

2. Describe your requirement using Ask AI

Once the JS Code step opens, you'll see a text area with the placeholder "Provide a high-level description..."

Type what you want the code to do in plain English, then click ASK AI to generate the code automatically. You can also switch to CHAT to iterate on the output conversationally.

jscode2.png
#

3. Pass input values to your code

Under Input Values, define the variables your code will use. Each variable gets a name (e.g., rawEmail) and a value mapped from a previous step (e.g., body.email).

Click ADD VARIABLE to add more inputs. These variables are directly accessible inside your code by their names.

jscode3.png
#

4. View and edit the generated code

Click <> CODE to expand the code editor. This shows the JavaScript generated by Ask AI — you can review it, modify it, or write your own from scratch.

jscode4.pngScreenshot 2026-06-29 at 2.15.27 PM.png
📌

You don't have to use Ask AI. You can write your own JavaScript directly in the Code editor.

#

5. Test and save

Click TEST to run the step and verify the output. Once the result looks correct, click SAVE to commit the step to your workflow.

#

Real Use Cases

  • Split a full name into first and last name

  • Get current date and time in YYYY-MM-DD HH:MM:SS format

  • Check if a number is prime

  • Convert a string to uppercase

  • Extract the domain from a URL

  • Parse sender, subject, and body from a raw email string

#

Tips

  • Use {{stepN.fieldname}} syntax to reference output from this step in later actions

  • Learn how to write better AI prompts: How to Write a Prompt

#

Supported Preinstalled Libraries

These libraries are available in the JS Code environment without any imports needed:

json

[
  "form-data as FormData",
  "https",
  "crypto",
  "setTimeout",
  "axios",
  "jsonwebtoken as jwt",
  "lodash as _",
  "node-fetch as fetch",
  "cheerio",
  "moment",
  "fetch",
  "Buffer",
  "atob",
  "XMLParser",
  "XMLBuilder",
  "XMLValidator"
]