This is the backend server for the Spare A Bite web application, a platform that helps connect food donors with people in need. It handles food listings, food requests, reviews, and authentication using Firebase and MongoDB.
🔗 Spare A Bite API - Live Demo
- Authentication: Uses Firebase Admin SDK to verify Firebase-issued JWT tokens
- Middleware: Includes
verifyTokenandverifyEmailfor secure access control - Food Management: Full CRUD operations for food listings
- Request System: Handle food requests between users
- Review System: Submit and view reviews
- CORS Support: Secure cross-origin requests
- Uses Firebase Admin SDK to verify Firebase-issued JWT tokens.
verifyTokenmiddleware checks for valid Bearer token.verifyEmailmiddleware ensures the user can only access their own data.
Follow these steps to run the Spare A Bite API on your local machine:
git clone https://github.com/your-username/spare-a-bite-server.git
cd spare-a-bite-servernpm install
# or
yarn installCreate a .env file in the root directory with the following:
PORT=5000
MONGO_URI=your_mongodb_connection_string
FIREBASE_PROJECT_ID=your_firebase_project_id
FIREBASE_PRIVATE_KEY=your_firebase_private_key
FIREBASE_CLIENT_EMAIL=your_firebase_client_emailnpm start
# or
yarn startThe API will be available at http://localhost:5000
GET /allFoods– All food dataGET /featuredFoods– Top 6 by quantityGET /foods?search=&sort=– Filtered/search foodGET /food/:id– Food by IDPOST /food– Add food (auth required)POST /food/:id– Edit food (auth required)DELETE /food/:id– Delete food (auth required)
POST /foodRequets– Make a request (auth required)GET /foodRequests?email=– See requests by user (auth + email match)DELETE /foodRequests/:id– Cancel a requestPATCH /foodRequests/:id– Edit request note (auth + email match)
GET /myManagedFoods?email=– View foods by donor (auth + email match)
GET /reviews– All reviewsPOST /reviews– Add review (auth required)