This README provides a step-by-step guide to building a CRUD (Create, Read, Update, Delete) application for managing NBA player posters. The app is built using Vite as the front-end framework, React Router for routing, MySQL for the database, and styled-components for styling. The backend uses express and utilizes custom API error handling, controllers for CRUD operations, and routes.
- Features
- Getting Started
- Prerequisites
- Setting Up the Database
- Usage
- Backend Configuration
- Folder Structure
- API Endpoints
- Deployment
- Technologies Used
- Author
- Contributing
- License
- Documentation
- Create: Easily add new NBA player posters by providing player details and an image URL.
- Read: View the list of NBA player posters with their names, teams, positions, and poster images.
- Update: Edit player information, including their name, team, position, and poster image.
- Delete: Remove a player poster from the database with a single click.
To get started with the Jobs Manager API, follow the instructions in the sections below.
Before getting started, ensure you have the following prerequisites installed:
- Node.js
- npm (Node Package Manager)
- MySQL
- MySQL Workbench
- Vite (You can install it globally with
npm install -g create-vite
) - React Router (installed as a dependency in your Vite project)
-
Launch MySQL Workbench and create a new database for your project.
-
Design the
players
table within the database, including columns such asid
,name
,description
,position
,team
,price
, andimage
. -
Insert some sample data into the
players
table.
-
Create a
.env
file in the project root directory and set the following environment variables:- MONGODB_URI: Your MongoDB connection URI.
- JWT_SECRET: A secret key for JWT token generation.
- JWT_LIFETIME: The lifetime of the JWT token in seconds.
- PORT: The port to run the server on.
-
Start the server:
npm start
The API should be accessible at http://localhost:8000 by default.
- Start the client:
cd frontend
npm run dev
The client should be accessible at http://localhost:5173 by default.
-
Set up a Node.js project for your backend.
-
Install the required packages, including
express
,mysql2
, andhttp-status-codes
. -
Create an Express application, set up a MySQL connection, and implement custom error handling.
-
Design the routes for Create, Read, Update, and Delete operations for NBA player posters.
-
Implement controllers for these CRUD operations, which interact with the database.
backend
├── README.md
├── .env
├── controllers
│ ├── players.js
├── db
│ ├── connect.js
└── errors
└── players.js
├── middlewares
│ ├── not-found.js
├── routes
│ ├── players.js
├── index.js
frontend
├── README.md
├── .env
├── frontend
│ ├── index.html
│ ├── index.js
│ ├── public
│ │ ├── favicon.ico
│ │ ├── logo192.png
│ │ ├── logo512.png
│ │ ├── manifest.json
│ │ └── robots.txt
│ └── vite.config.js
└── vite.config.js
-
Create
POST /players
-
Read
GET /players
-
Update
PUT /players/:id
-
Delete
DELETE /players/:id
-
Start the backend server by navigating to the
backend
directory and running:npm start
. -
Start the Vite development server for the frontend by navigating to the
frontend
directory and running:npm run dev
. -
Open a web browser and access your application at
http://localhost:5173
for the frontend andhttp://localhost:your-backend-port
for the backend.
- Node.js
- npm (Node Package Manager)
- MySQL
- MySQL Workbench
- Vite (You can install it globally with
npm install -g create-vite
) - React Router (installed as a dependency in your Vite project)
- Express
- http-status-codes
- cors
If you would like to contribute to the project, please read the Contributing Guide.
This project is licensed under the MIT License.
You can find the documentation for this project on GitHub: https://github.com/alyconr/NodeJs-Jobs-Api/blob/main/README.md