JudgeLib

NPM Library

Install JudgeLib directly into your Node.js application for seamless code execution capabilities.

npm install lib-judge

Why Choose NPM Library?

Zero Configuration

Install and start executing code immediately with sensible defaults and automatic setup.

Horizontal Scaling

Scale your code execution capacity by deploying multiple instances behind a load balancer.

Local Execution

Execute code locally within your application without external dependencies or network calls.

Installation Guide

1Install Package
Add lib-judge to your Node.js project

Using npm

npm install lib-judge

Using yarn

yarn add lib-judge
2Basic Usage
Start executing code in your application

JavaScript (ES Modules)

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);

Supported Languages

Python

3.11

.py

Java

17

.java

C++

GCC 11

.cpp