This project is an online compiler that supports running code in multiple programming languages, including Python, C++, and Node.js. It consists of a Node.js backend and a simple frontend to provide an easy-to-use interface for users to write and execute code.
- Multiple Languages Supported: Python, C++, and Node.js
- Error Handling: Compilation and runtime errors are captured and displayed
- Temporary Files: User code is saved to temporary files for execution
- Secure Execution: User code is isolated and executed in a controlled environment
.
├── public
│ ├── index.html
│ ├── style.css
│ └── script.js
├── temp
├── serv.js
└── README.md
public/
: Contains the frontend files (HTML, CSS, JavaScript)temp/
: Directory for temporary files created during code executionserv.js
: The main backend server codeREADME.md
: Project documentation
- Node.js and npm installed
- Python installed
- GCC, G++ (for compiling C++ code)
- Clone the repository:
git clone https://github.com/sanjay-gangwar4410/online-compiler.git
cd online-compiler
- Install dependencies:
npm install
node serv.js
The server will start and listen on port 4000. Open your browser and navigate to http://localhost:4000
to use the compiler.
- Select Language: Use the dropdown menu to select the language you want to write and execute code in (Python, C++, or Node.js).
- Write Code: Enter your code in the editable
div
provided. - Run Code: Click the "Run" button to execute your code. The output or error messages will be displayed below the editor.
The backend is built with Node.js and Express. It handles code execution for different languages as follows:
- Python and Node.js: The code is executed directly, and any output or errors are captured and returned to the client.
- C++: The code is first compiled using
g++
. If there are compilation errors, they are returned to the client. If the compilation is successful, the compiled executable is run, and any output or errors are captured and returned.
The frontend consists of a simple HTML page with a dropdown for language selection, an editable div for entering code, and a button to run the code.
This project is licensed under the MIT License.