This is the backend API for the Flashcard Learning Tool, built using Node.js, Express, and MySQL. The API provides endpoints for managing flashcards, including creating, reading, updating, and deleting flashcards.
- Express.js: Handles the routing and middleware.
- MySQL: Used as the relational database to store flashcards.
- CORS: Enables cross-origin requests.
- Body-Parser: Parses incoming JSON requests.
Ensure you have the following installed on your system:
- Node.js (v12.x or later)
- MySQL (v5.7 or later)
- npm (v6.x or later)
-
Clone the repository:
git clone <repository-url> cd flashcard-backend
-
Install dependencies:
npm install
-
Create a
.env
file in the root directory and add the following environment variables:PORT=5000 DB_HOST=your_database_host DB_USER=your_database_user DB_PASSWORD=your_database_password DB_NAME=your_database_name DB_PORT=your_database_port
-
Set up your MySQL database:
- Create a MySQL database.
- Create a table named
flashcards
with the following schema:CREATE TABLE flashcards ( id INT AUTO_INCREMENT PRIMARY KEY, question VARCHAR(255) NOT NULL, answer TEXT NOT NULL );
-
Start the server:
npm start
The server will start on the port specified in the
.env
file (default: 5000). -
API Endpoints:
- GET /api/flashcards
- Retrieves all flashcards from the database.
- POST /api/flashcards
- Creates a new flashcard.
- Body:
{ "question": "What is Node.js?", "answer": "Node.js is a JavaScript runtime built on Chrome's V8 engine." }
- PUT /api/flashcards/:id
- Updates an existing flashcard by its ID.
- Body:
{ "question": "What is Express.js?", "answer": "Express.js is a web application framework for Node.js." }
- DELETE /api/flashcards/:id
- Deletes a flashcard by its ID.
- GET /api/flashcards
-
Test the API:
- You can use tools like Postman to test the API endpoints.
To deploy this application, you can use services like Heroku, AWS, or any other cloud provider that supports Node.js applications.
If you would like to contribute to this project, please fork the repository and submit a pull request with your changes.
This project is licensed under the MIT License. See the LICENSE file for details.
Replace `<repository-url>` with your actual GitHub repository URL if applicable. This README provides clear instructions on setting up, running, and using the API, along with the necessary environment configuration.