/execute-js

The /execute-js endpoint allows users to execute JavaScript code securely on the server and retrieve the output.

URL

https://node.nodetrigger.com/execute-js

Method

POST

Request Body

  • code: A string containing the JavaScript code to be executed.

Response

  • On success: Returns a JSON object containing the output of the executed JavaScript code.
  • On error: Returns a JSON object with an error message and additional details.

Usage

Example 1: Simple JavaScript Code Execution

Request:

curl -X POST https://node.nodetrigger.com/execute-js \
-H "Content-Type: application/json" \
-d '{"code": "(() => { return 2 + 2; })()"}'

Response:

{
    "output": 4
}

Example 2: More Complex JavaScript Code Execution

Request:

curl -X POST https://node.nodetrigger.com/execute-js \
-H "Content-Type: application/json" \
-d '{"code": "(() => { const date = new Date(); return date.toISOString(); })()"}'

Response:

{
    "output": "2024-06-09T12:34:56.789Z"
}

Usage in Make

In Make, you can simply use the ‘Execute Javascript Code’ module and enter your Javascript code.

/execute-js

Notes

  • Ensure the JavaScript code is provided in the request body as a JSON string.
  • When writing the JavaScript code, make sure to return the result that you want to retrieve. This is necessary because the endpoint captures and returns the output of the executed script, which is the value returned by the code. If the code does not explicitly return a value, the output will be undefined.