A robust Node.js/Express backend API powering the MAK Tech service platform with authentication, image handling, and admin capabilities.
- Features
- Tech Stack
- Getting Started
- Environment Variables
- API Endpoints
- Authentication
- Database Schema
- File Upload
- Error Handling
- Contributing
- π JWT-based Authentication & Authorization
- π₯ User Management (Admin, Moderator, User roles)
- πΈ Image Upload with Cloudinary Integration
- πΌ Service Management System
- π Testimonial System
- π Contact Form Handler
- π‘οΈ Input Validation using Zod
- π CORS Enabled API
- π MongoDB Database Integration
- Runtime:
Node.js - Framework:
Express.js - Database:
MongoDBwithMongoose - Authentication:
JWT,bcryptjs - File Upload:
Multer,
Cloudinary
- Validation:
Zod - Other Tools:
Cors,
dotenv
# Clone the repository
git clone <repository-url>
# Install dependencies
npm install
# Start development server
npm startThe server will start on port 3000 by default.
Create a
.env
file in the root directory:
PORT=3000
ALLOWED_CLIENTS=
MONGO_URI=your_mongodb_uri
SALT_ROUNDS=13
JWT_SECRET=your_jwt_secret
JWT_EXPIRES_IN=1d
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secretPOST /auth/register- Register new userPOST /auth/login- User loginGET /auth/user- Get user profilePATCH /auth/update-password- Update passwordPOST /auth/update-email- Update emailPOST /auth/update-phone- Update phone
GET /admin/users- Get all usersPOST /admin/users/add- Add new userGET /admin/users/:id- Get user by IDPATCH /admin/users/update/:id- Update userDELETE /admin/users/delete/:id- Delete user
GET /api/services- Get all servicesGET /api/services/:id- Get service by IDPOST /admin/services/add- Add new servicePATCH /admin/services/update/:id- Update serviceDELETE /admin/services/delete/:id- Delete service
POST /api/upload/upload-image- Upload image with detailsGET /api/upload/getForm- Get all uploaded imagesPUT /api/upload/profile/:id- Update image details
The API uses JWT (JSON Web Tokens) for authentication. Include the token in the Authorization header:
Authorization: Bearer <your_jwt_token>{
username: String,
email: String,
password: String, // Hashed
phone: String,
role: String, // 'user', 'admin', 'moderator'
avatar: String,
privateNote: String
}{
name: String,
description: String,
price: String,
image: String
}Images are handled using Multer for temporary storage and Cloudinary for permanent cloud storage. Supported formats:
- JPEG
- PNG
- GIF
- WebP
The API implements a centralized error handling middleware that returns errors in the format:
{
"success": false,
"message": "Error description",
"extraDetails": "Additional error context"
}- Fork the repository
- Create your feature branch:
git checkout -b feature/name - Commit your changes:
git commit -m 'Add feature' - Push to the branch:
git push origin feature/name - Submit a pull request
Made with β€οΈ by Mian Ali Khalid