File size: 345 Bytes
b5ee24a
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { exec } from "child_process";

export function runCode(code) {
  return new Promise((resolve) => {
    exec(
      `node -e "${code.replace(/"/g, '\\"')}"`,
      { timeout: 2500 },
      (err, stdout, stderr) => {
        if (err) return resolve({ error: stderr || "Crash" });
        resolve({ output: stdout });
      }
    );
  });
}