The JavaScript SDK for Judge0 (@judge0/judge0-js) — a faithful port of the official judge0-python design and API.
import { run, PYTHON } from '@judge0/judge0-js';
const result = await run({
source_code: 'print("hello, world")',
language: PYTHON,
});
console.log(result.stdout);npm install @judge0/judge0-jsGet your API key from RapidAPI or ATD.
Judge0 has two flavors: Judge0 CE and Judge0 Extra CE. When using Rapid or ATD you may need to subscribe to both if you want access to all languages.
import { RapidJudge0CE, run } from '@judge0/judge0-js';
const client = new RapidJudge0CE('your-rapid-api-key');
const result = await run({
client,
source_code: 'print("hello, world")',
language: 'PYTHON',
});
console.log(result.stdout);Available clients:
RapidJudge0CEATDJudge0CERapidJudge0ExtraCEATDJudge0ExtraCEJudge0CloudCE(preview endpoint)
Set one of the following environment variables:
JUDGE0_RAPID_API_KEYJUDGE0_ATD_API_KEY
The SDK will automatically create the appropriate client.
import { run, PYTHON } from '@judge0/judge0-js';
const result = await run({
source_code: 'print("hello, world")',
language: PYTHON,
});
console.log(result.stdout);import { run, PYTHON } from '@judge0/judge0-js';
const result = await run({
source_code: 'print("hello, world")',
language: PYTHON,
});
console.log(result.stdout);import { run, C } from '@judge0/judge0-js';
const sourceCode = `
#include <stdio.h>
int main() {
printf("hello, world\\n");
return 0;
}
`;
const result = await run({
source_code: sourceCode,
language: C,
});
console.log(result.stdout);import { run, JAVA } from '@judge0/judge0-js';
const sourceCode = `
public class Main {
public static void main(String[] args) {
System.out.println("hello, world");
}
}
`;
const result = await run({
source_code: sourceCode,
language: JAVA,
});
console.log(result.stdout);import { run, C } from '@judge0/judge0-js';
const sourceCode = `
#include <stdio.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
printf("%d\\n", a + b);
char name[10];
scanf("%s", name);
printf("Hello, %s!\\n", name);
return 0;
}
`;
const stdin = `
3 5
Bob
`;
const result = await run({
source_code: sourceCode,
stdin,
language: C,
});
console.log(result.stdout);import { run, PYTHON } from '@judge0/judge0-js';
const results = await run({
source_code: "print(f'Hello, {input()}!')",
language: PYTHON,
test_cases: [
["Bob", "Hello, Bob!"], // tuple-style (array)
{ input: "Alice", expected_output: "Hello, Alice!" },
["Charlie", "Hello, Charlie!"],
],
});
for (const [i, result] of results.entries()) {
console.log(`--- Test Case #${i + 1} ---`);
console.log(result.stdout);
console.log(result.status);
}import { run, Submission, PYTHON, C } from '@judge0/judge0-js';
const submissions = [
new Submission({
source_code: "print(f'Hello, {input()}!')",
language: PYTHON,
}),
new Submission({
source_code: `
#include <stdio.h>
int main() {
char name[10];
scanf("%s", name);
printf("Hello, %s!\\n", name);
return 0;
}
`,
language: C,
}),
];
const testCases = [
["Bob", "Hello, Bob!"],
["Alice", "Hello, Alice!"],
["Charlie", "Hello, Charlie!"],
];
const results = await run({
submissions,
test_cases: testCases,
});
for (let i = 0; i < submissions.length; i++) {
console.log(`--- Submission #${i + 1} ---`);
for (let j = 0; j < testCases.length; j++) {
const result = results[i * testCases.length + j];
console.log(`--- Test Case #${j + 1} ---`);
console.log(result.stdout);
console.log(result.status);
}
}import { asyncRun, wait, PYTHON } from '@judge0/judge0-js';
const submission = await asyncRun({
source_code: 'print("hello, world")',
language: PYTHON,
});
console.log(submission.stdout); // undefined / null (not finished yet)
await wait({ submissions: submission });
console.log(submission.stdout); // "hello, world\n"import { getClient } from '@judge0/judge0-js';
const client = getClient();
const languages = await client.getLanguages();
console.log(languages);The SDK exports the same convenient aliases as the Python SDK:
PYTHON, PYTHON3, PYTHON_FOR_ML, C, CPP, JAVA, JAVASCRIPT,
BASH, GO, RUST, RUBY, PHP, CSHARP, KOTLIN, SWIFT, ...You can use either the constants or language IDs / names.
import { File, run, PYTHON } from '@judge0/judge0-js';
const main = new File('main.py', 'print("from additional file")');
const result = await run({
source_code: 'import main',
additional_files: [main],
language: PYTHON,
});A complete standalone example (no bundler required) is available in the repository:
# Start a local server (from repo root)
python3 -m http.server 8080
# Then open:
# http://localhost:8080/examples/vanilla.htmlThe example at examples/vanilla.html demonstrates real usage of the built SDK in the browser (with the necessary shims).
| Variable | Client |
|---|---|
JUDGE0_RAPID_API_KEY |
RapidJudge0CE / Extra |
JUDGE0_ATD_API_KEY |
ATDJudge0CE / Extra |
If no keys are provided, the SDK falls back to Judge0's public preview endpoints (suitable for testing and development).
npm install
npm run build
npm testMIT — same license as the original Judge0 Python SDK.