A RESTful API service for tracking user activities with authentication and data persistence.
- User Management (Create/Update/Get)
- Activity Logging (Single/Batch)
- Activity History Retrieval
- Input Validation
- Error Handling
- Environment Configuration
- Node.js
- Express.js
- MySQL
- Express Validator
- CORS
- UUID
- Dotenv
- Node.js (v14 or higher)
- MySQL Server
- npm or yarn
-
Clone the repository:
git clone [your-repo-url] cd activity-logger-backend -
Install dependencies:
npm install
-
Create a
.envfile in the root directory with the following content:PORT=3000 DB_HOST=localhost DB_USER=your_db_user DB_PASSWORD=your_db_password DB_NAME=ActivityLogger -
Initialize the database:
- Make sure your MySQL server is running
- Send a POST request to
/init-dbendpoint to create required tables
- POST
/api/users- Create/Update user - GET
/api/users/:phone_number- Get user by phone number
- POST
/api/activities/single- Create a single activity - POST
/api/activities/batch- Create multiple activities - GET
/api/users/:userId/activities- Get activities for a user
The API implements comprehensive error handling for:
- Validation errors
- Database errors
- Not found errors
- Server errors
Development mode:
npm start- uuid (VARCHAR(36)) - Primary Key
- name (VARCHAR(255))
- phone_number (VARCHAR(20)) - Unique
- id (INT AUTO_INCREMENT) - Primary Key
- userId (VARCHAR(36)) - Foreign Key
- activity_name (VARCHAR(255))
- time_stamp (TIMESTAMP)
- activity_description (TEXT)
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License.