A robust backend API for a car rental platform built with Node.js, Express, MongoDB, and Firebase Authentication.
- π Firebase Authentication - Secure user authentication and authorization
- π Car Management - Complete CRUD operations for car listings
- π Booking System - Handle car reservations and booking status
- π Search & Filter - Search cars by model, location, and availability
- π€ User-specific Data - Manage user's cars and bookings
- π‘οΈ Security Middleware - Token verification and email validation
- βοΈ Cloud Ready - Configured for Vercel deployment
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB
- Authentication: Firebase Admin SDK
- Deployment: Vercel
Before running this project, make sure you have:
- Node.js (v14 or higher)
- MongoDB Atlas account
- Firebase project with service account
- npm or yarn package manager
git clone <repository-url>
cd DriveNest_Server
npm install
Create a .env
file in the root directory:
# MongoDB Connection
MONGODB_URI=your_mongodb_connection_string
# Firebase Service Account (Base64 encoded)
FB_SERVICE_KEY=your_base64_encoded_firebase_service_account
# Server Configuration
PORT=3000
- Go to Firebase Console
- Create a new project or use existing one
- Generate a service account key (JSON)
- Convert the JSON to base64 and set it as
FB_SERVICE_KEY
npm start
The server will start on http://localhost:3000
Method | Endpoint | Description | Auth Required |
---|---|---|---|
GET |
/cars |
Get all cars with optional filters | β |
GET |
/cars/:id |
Get single car details | β |
GET |
/my-cars |
Get user's cars | β |
POST |
/cars |
Add new car | β |
PATCH |
/cars/:id |
Update car details | β |
DELETE |
/cars |
Delete user's car | β |
Method | Endpoint | Description | Auth Required |
---|---|---|---|
GET |
/bookings |
Get user's bookings | β |
POST |
/bookings |
Create new booking | β |
PATCH |
/bookings/:id/date |
Update booking date | β |
PATCH |
/bookings/:id/status |
Update booking status | β |
availability
- Filter by availability statussearchQuery
- Search by car model or location
email
- User email (required for protected routes)
This API uses Firebase Authentication with custom middleware:
- Token Verification: Validates Firebase ID tokens
- Email Verification: Ensures request email matches token email
Authorization: Bearer <firebase-id-token>
DriveNest_Server/
βββ index.js # Main application file
βββ package.json # Dependencies and scripts
βββ vercel.json # Vercel deployment config
βββ .env # Environment variables
βββ README.md # Project documentation
- CORS: Configured for cross-origin requests
- Express JSON: Parse JSON request bodies
- Cookie Parser: Handle cookies
- Custom Auth: Firebase token verification
- Email Verification: Match request email with token
This project is configured for easy deployment on Vercel:
- Connect your GitHub repository to Vercel
- Set environment variables in Vercel dashboard
- Deploy automatically with each push
Make sure to set these in your deployment platform:
MONGODB_URI
FB_SERVICE_KEY
PORT
(optional, defaults to 3000)
Currently, no tests are configured. To add testing:
# Install testing dependencies
npm install --save-dev jest supertest
# Add test script to package.json
"test": "jest"
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the ISC License.
- Frontend Repository: [Add your frontend repo link]
- Live Demo: [Add your demo link]
If you have any questions or need help, please:
- Check the Issues page
- Create a new issue if needed
- Contact the development team
Built with β€οΈ for the DriveNest community