REST API for the Pizza App. Built with Node.js, Express, and MongoDB (Mongoose). Serves menu data (pizzas) and supports listing and adding pizzas.
- Node.js + Express — HTTP server and routes
- Mongoose — MongoDB ODM
- CORS — Cross-origin requests enabled for front-end
- dotenv (optional) — Environment variables from
.env
Back-end/
├── index.js # App entry, Express setup, DB connection
├── routes/
│ └── menu.js # Menu routes (/menu)
├── controller/
│ └── pizzaController.js
├── models/
│ └── Pizza.js # Pizza schema
├── .env.example # Example env vars (copy to .env)
└── package.json
- Node.js (v14+ recommended)
- MongoDB (local or MongoDB Atlas)
-
Clone and go to the Back-end folder
cd Back-end -
Install dependencies
npm install
-
Environment variables
Copy the example env file and set your MongoDB URI (and optional port):
cp .env.example .env
Edit
.envand set:MONGODB_URI— MongoDB connection string (e.g. Atlas or local)PORT(optional) — Server port, default3000
Important: Do not commit
.envor real credentials. -
Start the server
- Production:
npm start - Development (with auto-reload):
npm run dev
Server runs at
http://localhost:3000(or yourPORT). - Production:
Base URL: http://localhost:3000 (or your deployed URL).
| Method | Endpoint | Description |
|---|---|---|
| GET | /menu/pizzas |
Get all pizzas |
| POST | /menu/pizzas |
Create a new pizza (JSON body) |
- Response:
200— JSON array of pizza objects.
- Body (JSON):
name(string),ingredients(string),price(number),photoName(string).
soldOut(boolean) is optional, defaultfalse. - Success:
201— Created pizza object. - Errors:
406— Missing required field.409— Pizza with samenamealready exists.500— Server error.
Example request:
POST /menu/pizzas
Content-Type: application/json
{
"name": "Margherita",
"ingredients": "Tomato, mozzarella, basil",
"price": 12,
"photoName": "margherita.jpg",
"soldOut": false
}| Command | Description |
|---|---|
npm start |
Run server (node index.js) |
npm run dev |
Run with nodemon (auto-reload) |
npm test |
Placeholder (no tests yet) |
ISC