Install JudgeLib directly into your Node.js application for seamless code execution capabilities.
Install and start executing code immediately with sensible defaults and automatic setup.
Scale your code execution capacity by deploying multiple instances behind a load balancer.
Execute code locally within your application without external dependencies or network calls.
npm install lib-judge
yarn add lib-judge
import fs from 'fs'; import path from 'path'; import { judge } from 'lib-judge'; // Assuming code is a string of C++ source code const code = ` #include<iostream> #include<vector> using namespace std; int main(){ int n; cin>>n; vector<int> v(n); for(int i = 0;i<n;i++){ cin>>v[i]; } int c = 0; for(auto it:v){ c+=it; } cout<<c; return 0; }`; // Save to a temporary file const tmpDir = './tmp'; if (!fs.existsSync(tmpDir)) fs.mkdirSync(tmpDir); const tmpPath = path.join(tmpDir, `code_${Date.now()}.cpp`); fs.writeFileSync(tmpPath, code, 'utf-8'); // Call judge with the correct file path const result = await judge({ codePath: tmpPath,//path of the file ques_name: 'sum of array', input: '5 1 2 3 4 5 ### 3 1 2 3 ### 2 1 2', output: '15 ### 6 ### 3', language:'cpp', timeout: '2', sizeout: '64', }); console.log(result);
3.11
17
GCC 11