A farmer-to-customer marketplace: farmers list produce, customers browse, add items to a cart, and check out directly — no middlemen.
- Express REST API — products, farmers, orders, messages
- Shopping cart + checkout — real add-to-cart, quantity controls, and a checkout flow that creates a persisted order
- Contact Farmer — buyers can message a farmer directly about a listing
- Two data-layer options, same API either way:
db/jsonStore.js— a local JSON file (data/db.json). This is what runs by default, with zero setup.db/mongoStore.js+models/*.js— real MongoDB via Mongoose, ready to switch on.
npm install
npm startVisit http://localhost:3000 — the site, cart, and checkout all work immediately using the bundled JSON file as storage.
- Get a connection string — the easiest way is a free MongoDB Atlas cluster.
- Create a
.envfile in the project root:MONGO_URI=mongodb+srv://<user>:<password>@<cluster-url>/farmtrust - Restart the server. You'll see
[db] Connected to MongoDBin the console —db/index.jsautomatically switches from the JSON store todb/mongoStore.js, so no other code changes are needed. - Optional: write a small seed script using
models/Product.jsandmodels/Farmer.jsto load the same starter data into MongoDB (the JSON file indata/db.jsonis a ready-made reference for the fields each collection needs).
server.js Express app entry point
routes/api.js REST endpoints (products, farmers, orders, messages)
db/index.js Picks JSON store or MongoDB store based on .env
db/jsonStore.js Default file-based data layer
db/mongoStore.js MongoDB data layer (Mongoose)
models/ Mongoose schemas: Product, Farmer, Order, Message
data/db.json Seed data / default storage file
public/index.html Frontend: marketplace, cart, checkout, contact form
| Method | Route | Purpose |
|---|---|---|
| GET | /api/products | List produce (optional ?category=) |
| GET | /api/farmers | List farmers |
| POST | /api/orders | Place an order (cart checkout) |
| GET | /api/orders | List all placed orders |
| POST | /api/messages | Send a message to a farmer |
| GET | /api/messages | List all messages |
- All farmer names, farms, and prices are placeholder demo data.
- This is a demo-grade project: there's no authentication, and stock counts don't decrement on checkout. Both are reasonable next steps if you want to take this further.