Udacity is invested in creating bonding experiences for its employees and students. A bunch of team members got the idea to hold trivia on a regular basis and created a webpage to manage the trivia app and play the game, but their API experience is limited and still needs to be built out.
The application allows the following:
- Display questions - both all questions and by category. Questions should show the question, category and difficulty rating by default and can show/hide the answer.
- Delete questions.
- Add questions and require that they include question and answer text.
- Search for questions based on a text query string.
- Play the quiz game, randomizing either all questions or within a specific category.
This project makes use of ReactJS and Node for the frontend and Flask, SQLAlchemy and PostgreSQL for the backend. To be able to run this project locally, all aforementioned packages/libraries must be installed first.
-
Python 3.7 - Follow instructions to install the latest version of python for your platform in the python docs
-
Virtual Enviornment - We recommend working within a virtual environment whenever using Python for projects. This keeps your dependencies for each project separate and organaized. Instructions for setting up a virual enviornment for your platform can be found in the python docs
-
PIP Dependencies - Once you have your virtual environment setup and running, install dependencies by naviging to the
/backend
directory and running:
pip install -r requirements.txt
This will install all of the required packages we selected within the requirements.txt
file.
- Key Dependencies
-
Flask is a lightweight backend microservices framework. Flask is required to handle requests and responses.
-
SQLAlchemy is the Python SQL toolkit and ORM we'll use handle the lightweight sqlite database. You'll primarily work in app.py and can reference models.py.
-
Flask-CORS is the extension we'll use to handle cross origin requests from our frontend server.
With Postgres running, restore a database using the trivia.psql file provided. From the backend folder in terminal run:
psql trivia < trivia.psql
- From within the
backend
directory after making sure you are working using your created virtual environment, run the server with the following command:Setting theexport FLASK_APP=flaskr export FLASK_ENV=development flask run
FLASK_ENV
variable todevelopment
will detect file changes and restart the server automatically. Setting theFLASK_APP
variable toflaskr
directs flask to use theflaskr
directory and the__init__.py
file to find the application.
To run the tests, run:
dropdb udacity_trivia_test
createdb udacity_trivia_test
psql udacity_trivia_test < trivia.psql
python test_flaskr.py
This will populate the test database with data.
tip: this frontend is designed to work with Flask-based Backend. It is recommended you stand up the backend first, test using Postman or curl, then the frontend should integrate smoothly.
-
Installing Node and NPM
This project depends on Nodejs and Node Package Manager (NPM). Before continuing, you must download and install Node (the download includes NPM) from https://nodejs.com/en/download. -
Installing project dependencies
This project uses NPM to manage software dependencies. NPM Relies on the package.json file located in thefrontend
directory of this repository. After cloning, open your terminal and run:
npm install
tip: npm i is shorthand for npm install
The frontend app was built using create-react-app. In order to run the app in development mode use npm start
. You can change the script in the package.json
file.
Open http://localhost:3000 to view it in the browser. The page will reload if you make edits.
npm start
View the README.md in the backend folder for the API documentation
- Opeyemi Odebode
- The entire Udacity team!