Skip to content

JavaScript

JavaScript tools run on a V8 engine with a fresh VM for each execution and no state between calls.

The main file must be cortexone_function.js and export cortexone_handler:

function cortexone_handler(event, context) {
var result = { message: "Hello, World!" };
return { statusCode: 200, body: result };
}

event is the input payload; context is execution metadata. Return an object with statusCode and body — serialization is automatic.

function cortexone_handler(event, context) {
var numbers = event.num;
var sum = numbers.reduce(function(a, b) { return a + b; }, 0);
return { statusCode: 200, body: { sum: sum, mean: sum / numbers.length } };
}

Read environment variables via process.env. When enabled, fetch() returns a synchronous response object (not a Promise) with status, statusText, body (raw string), and headers:

var response = fetch("https://api.example.com/data");
var data = JSON.parse(response.body);
  • No require() or import.
  • No file system access.
  • Synchronous onlyasync/await, Promises, and setTimeout are not supported.
  • Fresh VM per execution, no persistent state.

Built-ins like JSON, Math, Date, Array, and console.log are available.

512 MB memory, 300-second runtime, 2.0-core CPU. Unhandled errors return 500; timeouts return 408. You can return non-200 status codes intentionally for validation failures.