This a full stack app using React, Node/Express, and MySQL. It is meant to be a game in which users have to spot errors in snippets of code. Initially, Javascript only.
- Run
npm installin project directory. cd clientand runnpm install.- JUST IN CASE it's absent in package.json: Also run
npm install @monaco-editor/react monaco-editorto be able to create the website IDE.
- Access the MySQL interface in your terminal by running
mysql -u root -p - Create a new database:
create database new-database - Add a
.envfile to the project folder of this repository containing the MySQL authentication information for MySQL user. For example:
DB_HOST=localhost
DB_USER=root
DB_NAME=NEWDATABASE
DB_PASS=YOURPASSWORD- Run
npm run migratein the project folder of this repository, in a new terminal window. This will create a table called 'snippets' in your database (see below)
Table: snippets
| Field | Type | Null | Key | Default | Extra |
|---|---|---|---|---|---|
| id | int | NO | PRI | NULL | auto_increment |
| code | text | YES | NULL | ||
| level | int | YES | NULL | ||
| tests | text | YES | NULL |
/api/snippets--> Home and Game (both GET and POST endpoints set up)/api/snippets/level/:level_id--> get snippets per level(level id is actually the level number).They arrive in a random order./api/snippets/:snippet_id--> to get specific snippet- Virtual Machine (vm) : Some explanation: we are using node:vm which is a virtual machine module. What it does, is to basically provide a virtual space to execute code when provided as string (as it is when we receive is from json.stringify). First there's a "context" creation, basically that space for the code to be executed. In that one, I have declared an empty array called results to push in both the code to be tested and the tests I would like to execute on that code.
/attempt/:question_id--> we use vm to POST the users corrected code attempt and test it. (it is based on the question_id which is basically the code id from the snippets table).
- Run
npm startin project directory to start the Express server on port 4000 - In another terminal, do
cd clientand runnpm run devto start the client in development mode with hot reloading in port 5173.
- if you cant the labeling click on it to see the image
This is a student project that was created at CodeOp, a full stack development bootcamp in Barcelona by Loretta Savvidou in collaboration with TO BE COMPLETED.