qCompiler is a versatile Node.js library designed for building online or offline code compiler applications. It enables seamless compilation for various languages on the server, providing outputs swiftly and efficiently.
qCompiler offers a user-friendly solution for developers who want to integrate code compilation into their applications. Whether you are building an educational platform, have coding challenges, or need a reliable code compilation service, qCompiler streamlines the process.
qCompiler is currently in the initial development stage. As the library grows, so does the list here.
Language | Support |
---|---|
C | ✔ |
C++ | ✔ |
Java | ✔ |
Python | ✔ |
All the APIs are written for
-
${\color{yellow}Receive\ Code\ and\ Input\ Data:}$ Get the program and input data from the client as requested. -
${\color{yellow}Compile\ the\ Program:}$ Utilize the qCompiler module to compile the program. -
${\color{yellow}Retrieve\ Output\ and\ Errors:}$ Obtain the output and errors in JSON and string formats. -
${\color{yellow}Respond\ to\ the\ Client:}$ Send the output back to the client.
Before utilizing qCompiler, ensure that the necessary compilers for the target programming languages are set up on the server. Necessary guidelines can be found here.
To install
npm i qcompiler
Define the basic configurations to compile your program.
const config = {
standard: "c11",
cmd: "gcc",
executionCmd: 'java', //only for java
timeout: 2000,
}
You can define any valid standard that supports your machine's compiler. standard
is applicable only for C and C++.
Default standard
:
Language | Default Value |
---|---|
C | "c11" |
C++ | "c17" |
cmd
and executionCmd
are the commands to compile or run your program.
Default values for cmd
for several languages are:
Language | Default Value |
---|---|
C | "gcc" |
C++ | "g++" |
Java | "javac" |
Python | "python" |
executionCmd
is necessary for Java only. Default value javac
.
// If the environment variable is set
cmd: "command"
// If the environment variable is not set
cmd: "path/to/command/yourCommand"
// Example
cmd: "C:\MinGW\bin\gcc"
In milliseconds the maximum amount of time the program is allowed to run. Default: 1000ms.
To compile a C program you can use the following template.
const compiler = new QCompiler(config);
const response = await compile.compileC(code, input);
console.log(response)
To compile a C++ program you can use the following template.
const compiler = new QCompiler(config);
const response = await compile.compileCpp(code, input);
console.log(response)
To compile a Java program you can use the following template.
const compiler = new QCompiler(config);
const response = await compile.compileJava(code, input);
console.log(response)
To compile a Python program you can use the following template.
const compiler = new QCompiler(config);
const response = await compile.compilePython(code, input);
console.log(response)
// data.status = boolean | string
// data.output = Output value | undefined
// data.error = Error message (if status == false) | undefined
// executionTime = total execution time in milisecond | undefined
For the most up-to-date information and usage guidelines, please take a look at the official documentation. Explore the power of code compilation with qCompiler – the comprehensive solution for seamless integration and efficient processing.
All the contents in this repository are released under the MIT License.