This backend project is developed using Node.js, Express.js, and MongoDB. It offers APIs for user authentication, creating and viewing service listings, and booking services. Tested and verified using RapidAPI Client.
- Node.js
- Express.js
- MongoDB + Mongoose
- JWT Authentication
- Dotenv
- Cors
- User Registration and Login (JWT-based authentication)
- Create and Fetch Service Listings
- Book a Service and Track Booking Status
- MongoDB Schema Validation with Mongoose
- Protected Routes using Middleware
- Initialized Node.js project with
npm init - Installed dependencies:
npm install express mongoose dotenv cors bcryptjs jsonwebtoken
- Folder Structure:
backend/ ├── config/ ├── controllers/ ├── middleware/ ├── models/ ├── routes/ ├── .env ├── index.js
.envFile:PORT=5000 MONGODB_URI=paste your uri here JWT_SECRET=mysecretkey
- Connected to MongoDB using Mongoose inside
config/db.js - Imported the connection in
index.js - Handled success and failure logs
- Model:
User(name, email, password) - Routes:
POST /api/auth/register– Register a new userPOST /api/auth/login– Login and get JWT token
- Password hashed with
bcryptjs, token generated withjsonwebtoken - Middleware:
authMiddleware.jsto protect routes
- Model:
Service(title, description, price ,category) - Routes:
POST /api/services– Add a service (Protected)GET /api/services– Fetch all services
- Model:
Bookinguser→ referencesUserservice→ referencesServicestatus(default: Confirmed)
- Routes:
POST /api/bookings– Book a service (Protected)GET /api/bookings– Get all bookings for the logged-in user
- Endpoint:
POST /api/auth/register - Body:
{ "name": "Ravi", "email": "ravi@google.com", "password": "1234" }
- Endpoint:
POST /api/auth/login - Body:
{ "email": "ravi@google.com", "password": "1234" } - ✅ Returns JWT token
- Endpoint:
POST /api/services - Headers:
{ "Authorization": "Bearer <your_jwt_token>" } - Body:
{ "title": "AC Repair", "description": "Air conditioner maintenance and repair", "Price" : 1000 "category": "Repair" }
- Endpoint:
GET /api/services
- Endpoint:
POST /api/bookings - Headers:
{ "Authorization": "Bearer <your_jwt_token>" } - Body:
{ "service": "<service_id>" }
- Endpoint:
GET /api/bookings - Headers:
{ "Authorization": "Bearer <your_jwt_token>" }
-
Start Server:
cd backend (navigate to backend folder) node index.js (run index.js file) -
Server:
MongoDB Connected 👍👍 Server is running on http://localhost:5000
---