JavaScript Executor
Our Run JavaScript Code
module allows you to run Python code on the
Bun runtime, inside a relatively standard Linux environment.
Bun is almost completely compatible with Node.js, you can
assume that it works the same. You can find the API docs
here.
Overview
You can currently configure only the code here. The code must be valid JavaScript (not TypeScript) code, and will run on the Bun runtime. You can use any npm package you want, it will be installed automatically.
Printing something to the console has absolutely no effect. Make sure that you
return values either by assigning to the global result
variable (which must
not be redeclared), or by using a top-level return
statement.
Do not use import
to import packages, that will cause a syntax error. Instead,
use require
.
You can use top-level await if you are performing anything asynchronous.
Pricing
The JavaScript executor costs 50 credits per execution (of up to 3 minutes).
Examples
This section presents a couple of very basic JavaScript examples. They are mostly there to show how to return data from the code executor. If you want to learn JavaScript (Node.js) itself, take a look here.
function multiplyNumbers(number1, number2) {
return number1 * number2;
}
// assign to top-level result variable
result = {
data: multiplyNumbers(54, 67);
};
// top-level await
const response = await fetch("https://www.0codekit.com");
// top-level return
return {
data: await response.text(),
};
// just require any npm package you like
const _ = require("lodash");
return {
data: _.partition([1, 2, 3, 4], (n) => n % 2),
};