In this article, I will explain how I made my own online compiler using open-source code.
Here I will make one editor that supports 3 languages; C++, Java, and Python.
Building an online code editor and compiler can seem too complicated, but we can break it down into two pieces.
- API running on the backend server, which will take a piece of code and language as input and output the answer after running the code on the server
- Frontend code editor, we can choose the language and edit and modify the code here. Then we make a post request to the backend API and show output on the website
- Deploy our Online Code Executor in Google Cloud
- Understanding the API of Judge0
- Creating an online code editor front-end (this tutorial)
This is the webpage we are going to build.
Our frontend is pretty simple. We have one drop-down menu where we can select the language and depend upon the language we will get our respective code editors. Our main code lies in the home-page.html and the code-editor resides in the texteditor.js.
Here we have made one onClickListener for dropdown menu items. So when one item is clicked, the corresponding listener gets triggered and we can call our desired editors. All the languages have different id associated with it . The list can be found using this.
We add the style from assets/css/style.css .
language_id. We also set default values to the editor depending on the
On execution of code it should show like this.
The entire code can be found in the following repository.
Ace (Ajax.org Cloud9 Editor)
This repository has only generated files. If you want to work on ace please go to https://github.com/ajaxorg/ace instead.
here you can find pre-built files for convenience of embedding. it contains 4 versions
- src concatenated but not minified
- src-min concatenated and minified with uglify.js
- src-noconflict uses ace.require instead of require
- src-min-noconflict concatenated, minified with uglify.js, and uses ace.require instead of require