Backend for both the Educado webpage (content creator page) and the Educado mobile application (student page). It mainly serves the webpage and application with data from the database.
Main dependencies:
- Nodejs
- Express
- MongoDB/Mongoose
- Axios
Below is a short guide explaining how to set up and run the educado backend in development mode.
- Ensure that local version of Node.js is latest stable version (v20.10.0, at the time of writing this)
- run
node --version
- if version == v20.10.0, then all is good :)
- if version is NOT v20.10.0 then do the following
- Ensure that you have npm installed
- run
npm install -g n
to install node version manager - when installed, run
n stable
, to install latest stable version of node
- run
- Download MongoDB Compass (GUI)
- Download Docker
- Go to GitHub page and clone (with ssh or GitHub Desktop) the repository
- Create .env file and gcp_service.json file, for development keys in /config directory
- Get the .env and json file from whoever is in charge of the secrets. The 2023 responsible was Frederik Bode Thorbensen: from Software semester 7 of AAU CPH. The dev keys contain the following values:
- GOOGLE_CLIENT_ID
- GOOGLE_CLIENT_SECRET
- MONGO_URI
- MONGO_URI_TEST
- TOKEN_SECRET
- COOKIE_KEY
- GOOGLE_APPLICATION_CREDENTIALS
- GMAIL_USER
- GMAIL_APP_PASSWORD
- type
- project_id
- private_key_id
- private_key
- client_email
- client_id
- auth_uri
- token_uri
- auth_provider_x509_cert_url
- client_x509_cert_url
- universe_domain
Remember, these secrets are exactly that... Secrets... So make extra sure they are git-ignored (or someone will be very mad)
- In root folder of the repo run
npm install
- Run
npm install
again
- Run
npm run dev
to start application - Rest api runs on ://localhost:8888
- Run
npm run prod
to start application - Rest api runs on ://localhost:8888
-
npm run docker
- Description: Starts the Docker containers in the background.
- Command:
docker-compose up -d
-
npm run docker_down
- Description: Stops and removes the Docker containers defined in the Docker Compose configuration.
- Command:
docker-compose down
-
npm run docker_build
- Description: Builds and starts the Docker containers in the background. This command will rebuild the containers even if there are cached layers available.
- Command:
docker-compose up -d --build
-
npm run docker_clean_db
- Description: Stops and removes the Docker containers and the volume associated with the MongoDB container, and then starts the MongoDB container with a fresh build. This command is useful for resetting the database to a clean state.
- Command:
docker-compose down && docker volume rm educado-backend_mongodb_data && docker-compose up -d --build mongodb
- It’s important to use the appropriate command depending on whether you are in a development or production environment.
- The Docker commands are intended to be run in an environment where Docker is installed and configured.
- Ensure that no other services are running on the ports that are configured in
docker-compose.yml
to avoid port conflicts.