This project is a Node.js-based backend for the Gym Rat fitness tracking application. It uses Express.js to manage API endpoints, PostgreSQL as the database, and Passport.js for authentication. The API allows users to manage their accounts, track exercises, log entries, and participate in workout programs.
- User Authentication: Register and login functionalities using email, username, and password.
- Exercise Management: Retrieve and manage different exercises based on muscle groups.
- Workout Entry Management: Add, update, and delete workout entries.
- Workout Programs: Manage workout programs with related exercises.
- Favorite Exercises: Retrieve frequently used exercises by a user.
- CORS Support: Allow cross-origin requests from a front-end client hosted at
http://localhost:5173
. - JWT Authentication: Secure routes with JSON Web Tokens (JWT).
- Node.js: Backend runtime environment.
- Express.js: Web framework for handling routes and requests.
- PostgreSQL: Relational database for storing users, exercises, entries, and programs.
- Passport.js: Authentication middleware for Node.js.
- bcrypt.js: Password hashing library.
- JWT (JSON Web Token): Token-based authentication.
- CORS: Cross-Origin Resource Sharing configuration.
- dotenv: Manage environment variables securely.
- Node.js (v12 or higher)
- PostgreSQL database
- npm (Node Package Manager)
-
Clone this repository:
git clone https://github.com/yourusername/fitness-tracker-api.git cd fitness-tracker-api
-
Install the dependencies:
npm install
-
Create a
.env
file in the root directory with the following environment variables:PG_USER=<your_postgresql_username> PG_HOST=<your_postgresql_host> PG_DATABASE=<your_postgresql_database_name> PG_PASSWORD=<your_postgresql_password> PG_PORT=<your_postgresql_port> JWT_SECRET=<your_jwt_secret>
-
Start the PostgreSQL server and ensure your database is properly configured.
-
Start the development server:
npm start
-
The server will run on
http://localhost:3000
.
Import the database from gym-rat-web-database.sql. Find the SQL Queries at databaseQueries.sql.
- POST /login: User login with email and password.
- POST /register: Register a new user account.
- POST /all-exercises: Retrieve all exercises.
- POST /exercises: Retrieve exercises by muscle group.
- POST /exercise: Retrieve a specific exercise by ID.
- POST /entries: Retrieve all entries for a specific user and exercise.
- POST /last-entries: Retrieve all entries for a specific user, including exercise details.
- POST /add-entry: Add a new workout entry.
- POST /update-entry: Update an existing workout entry.
- POST /delete-entry: Delete a specific workout entry.
- POST /programs: Retrieve all workout programs.
- POST /program: Retrieve details of a specific program by ID.
- POST /program-exercises: Retrieve exercises associated with a specific program.
- POST /delete-user: Delete a user and all their workout entries.
- POST /favorites: Retrieve a user's favorite exercises based on workout frequency.
- POST /total-entries: Retrieve the total number of entries for a user.
This project is licensed under the MIT License. See the LICENSE file for details.