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
verifyToken
andverifyEmail
for 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.
verifyToken
middleware checks for valid Bearer token.verifyEmail
middleware 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-server
npm install
# or
yarn install
Create 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_email
npm start
# or
yarn start
The 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)