Skip to content
Public template

About

React code editor with a Run button: 46 languages through OnlineCompiler.io, with the API key kept on the server.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

React code editor with a Run button

A code editor in one React component: CodeMirror, a language menu, an input box and a Run button. Run sends the code to a small route on your own server, which adds your API key and calls OnlineCompiler.io. The program runs in a sandbox and the output, errors and exit code come back to the page. The API key stays on the server.

The menu ships with Python, JavaScript, C++ and Java. The API runs 46 languages, and adding one is a new entry in src/App.jsx.

The editor after pressing Run on the Python starter

Setup

Needs Node 20.6 or newer.

git clone https://github.com/onlinecompiler-io/react-code-editor.git
cd react-code-editor
npm install
cp .env.example .env.local   # then put your key in .env.local

Get a free API key at https://api.onlinecompiler.io/compilers/api-keys/?utm_source=github&utm_medium=repo&utm_campaign=react-code-editor and set it in .env.local:

ONLINECOMPILER_API_KEY=your_api_key

Start the route and the React app in two terminals, then open http://localhost:5173:

# Terminal 1: the route, on port 3001
npm run server

# Terminal 2: the React app
npm run dev

To run it as one server, build the page once. Express then serves the app and the route together on http://localhost:3001:

npm run build
npm run server

How the key stays on the server

server.js is the only file that reads ONLINECOMPILER_API_KEY. The browser posts { compiler, code, input } to /api/run on your own server; the server adds the key as the Authorization header, posts to https://api.onlinecompiler.io/api/run-code-sync/, and passes the answer back. A key in browser code can be read by anyone who opens the page, so never name the variable VITE_...: Vite builds those into the code it sends to the browser. .env.local is ignored by git.

During development Vite serves the page and proxies /api to the Express server (see vite.config.js).

Anyone who can open your page can press Run. On a public site, put /api/run behind your own sign-in or a rate limit, and give the key a monthly limit of its own on the API keys page of your dashboard.

Next.js

nextjs/ is the same component with the route as an App Router route handler (app/api/run/route.ts). It needs no proxy.

cd nextjs
npm install
cp .env.example .env.local   # add your key
npm run dev

The guide

The full walkthrough, with the errors and limits the route can return, is at https://onlinecompiler.io/guides/react-code-editor-with-run-button?utm_source=github&utm_medium=repo&utm_campaign=react-code-editor.

License

MIT, 2026 RunCode Inc. See LICENSE.

About

React code editor with a Run button: 46 languages through OnlineCompiler.io, with the API key kept on the server.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages