viaSocket Help

Use JavaScript Code

JS Code Steps let workflows run small snippets of JavaScript code. These steps give you the flexibility to add custom logic to your workflows.

📌

You can use JS Code Steps as actions in your workflows to perform tasks like data manipulation, calculations, or interacting with external services.


When should i use JS code?

• Perform simple calculations or modify data.

• Handle complex logic that cannot be achieved with basic built-in actions

• Interact with external APIs and process the response data

• Manipulate or filter input data based on specific conditions.


#

Steps to add JS code to your workflow:

#

1. Add a JS code action

In the workflow editor, click Add Action and select JS Code from the built-in tools.


step 1.jpg
#

2. Generate your JS code using Ask AI

 Generate JavaScript code through the Ask AI feature by simply describing your requirement in plain english

language.

step 3.jpg
#

3. Test the Step

Click the “Test” button to run the step and check the result.


last step.png
#

📌

Some real use case where JS code is used:

• Split the full name input into first and last.

• Get the current date and time and return it in the format: YYYY-MM-DD HH:MM:SS as an object.

• Check if the value provided is prime.

• Convert the input string into uppercase letters

• Extract the domain name from the provided URL

Note: You can also write your own JS code instead of using Ask AI feature.

📌

How to write AI prompt using Ask AI feature : Check here

#

Supported Preinstalled Libraries:


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