DEV Community

Cover image for Let’s Develop an Online Code Editor/Compiler Like HackerRank
Nil Madhab
Nil Madhab

Posted on • Updated on

Let’s Develop an Online Code Editor/Compiler Like HackerRank

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.

Adding more languages is also very simple.
Alt Text


Building an online code editor and compiler can seem too complicated, but we can break it down into two pieces.

  1. 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
  2. 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

Tutorials in this Series

  1. Deploy our Online Code Executor in Google Cloud
  2. Understanding the API of Judge0
  3. Creating an online code editor front-end (this tutorial)


This is the webpage we are going to build.

you can find the live demo here

Online code editor demo


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.

The home-page looks like this.
Alt Text
The home-page html code is given below.

Here we call the codeEditor function of the javascript file , we pass the respective id associated with the language.

We add the style from assets/css/style.css .

Also we need to link the javascript file so that the code can be executed. We get the lang_id from the html and do the network call accordingly. For java code is 62, cpp 53 and python 70. This is passed in language_id . We also set default values to the editor depending on the lang_id.

On execution of code it should show like this.
Alt Text

The entire code can be found in the following repository.

Ace ( Cloud9 Editor)


Ace is a code editor written in JavaScript.

This repository has only generated files. If you want to work on ace please go to 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

For a simple way of embedding ace into webpage see editor.html or list of other simple examples To see ace in action go to kitchen-sink-demo, scrollable-page-demo or minimal demo,

Top comments (3)

limitcracker profile image
Ioannis Gyftakis

Hi, how we could also make Run Test feature in order to check for the solution?

tel profile image
Taha Elkarroumy

How to accept input from the user

shubhanshu2000 profile image
shubhanshu2000 • Edited

Use post method