Skip to content

Latest commit

 

History

History
201 lines (137 loc) · 5.27 KB

File metadata and controls

201 lines (137 loc) · 5.27 KB

🚗 DriveNest Server

A robust backend API for a car rental platform built with Node.js, Express, MongoDB, and Firebase Authentication.

✨ Features

  • 🔐 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

🛠️ Tech Stack

  • Runtime: Node.js
  • Framework: Express.js
  • Database: MongoDB
  • Authentication: Firebase Admin SDK
  • Deployment: Vercel

📋 Prerequisites

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

🚀 Quick Start

1. Clone the repository

git clone <repository-url>
cd DriveNest_Server

2. Install dependencies

npm install

3. Environment Setup

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

4. Firebase Setup

  1. Go to Firebase Console
  2. Create a new project or use existing one
  3. Generate a service account key (JSON)
  4. Convert the JSON to base64 and set it as FB_SERVICE_KEY

5. Start the development server

npm start

The server will start on http://localhost:3000

📡 API Endpoints

🚗 Cars

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

📅 Bookings

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

🔍 Query Parameters

Cars Endpoint (/cars)

  • availability - Filter by availability status
  • searchQuery - Search by car model or location

Authentication Endpoints

  • email - User email (required for protected routes)

🔒 Authentication

This API uses Firebase Authentication with custom middleware:

  1. Token Verification: Validates Firebase ID tokens
  2. Email Verification: Ensures request email matches token email

Headers Required for Protected Routes:

Authorization: Bearer <firebase-id-token>

🏗️ Project Structure

DriveNest_Server/
├── index.js          # Main application file
├── package.json       # Dependencies and scripts
├── vercel.json       # Vercel deployment config
├── .env              # Environment variables
└── README.md         # Project documentation

🔧 Middleware

  • 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

🌐 Deployment

Vercel Deployment

This project is configured for easy deployment on Vercel:

  1. Connect your GitHub repository to Vercel
  2. Set environment variables in Vercel dashboard
  3. Deploy automatically with each push

Environment Variables for Production

Make sure to set these in your deployment platform:

  • MONGODB_URI
  • FB_SERVICE_KEY
  • PORT (optional, defaults to 3000)

🧪 Testing

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"

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 License

This project is licensed under the ISC License.

🔗 Related Projects

  • Frontend Repository: [Add your frontend repo link]
  • Live Demo: [Add your demo link]

📞 Support

If you have any questions or need help, please:

  1. Check the Issues page
  2. Create a new issue if needed
  3. Contact the development team

Built with ❤️ for the DriveNest community