A minimal Book Tracker application built with the MERN stack (MongoDB, Express, React, Node). This repository contains a small, focused example you can run locally for learning, demos, or Hacktober contributions.
- Manage a personal collection of books (create, read, update, delete)
- Track reading status:
to-read,reading,read - Simple REST API consumed by a React + Vite frontend
- Persistent storage with MongoDB + Mongoose
- Tiny, easy-to-read codebase for quick contributions
- Frontend: React + Vite + TypeScript
- Styling: Tailwind CSS (configured in project)
- Backend: Node.js + Express
- Database: MongoDB (Mongoose ODM)
- Dev tools: dotenv, ESLint, TypeScript typecheck
- Node.js 18+ and npm
- A MongoDB connection (MongoDB Atlas or local instance)
Follow these steps to set up the Book Tracker locally. This repo keeps both the frontend and backend under the App/ folder. Start the backend API first, then the frontend.
First, fork the repository on GitHub, then clone your fork:
git clone https://github.com/YOUR-USERNAME/mern-book-tracker.git
cd mern-book-trackerAlternatively, if you just want to run it locally without contributing:
git clone https://github.com/debugfest/mern-book-tracker.git
cd mern-book-trackerOpen a terminal and run:
cd App/server
npm install
# Create a .env file in App/server with at least:
# MONGODB_URI='your-mongodb-connection-string'
# PORT=5000 # optional, defaults to 5000
# Start the server
npm run devBy default the server listens on http://localhost:5000 and exposes the API under /api.
Available endpoints:
- GET /api/books — fetch all books (sorted newest first)
- POST /api/books — create a book (body:
{ title, author, genre, year, status? }) - PUT /api/books/:id — update a book by id
- DELETE /api/books/:id — delete a book by id
Example: create a book with curl
curl -X POST http://localhost:5000/api/books \
-H "Content-Type: application/json" \
-d '{"title":"Sapiens","author":"Yuval Noah Harari","genre":"History","year":2011}'Open another terminal and run:
cd App
npm install
npm run devVite will print the local dev URL (usually http://localhost:5173). Open it to use the app.
To build the frontend for production:
cd App
npm run buildYou can deploy the frontend and backend separately, or optionally serve the built frontend from the Express server (requires adding a small static middleware to App/server/server.js).
mern-book-tracker/
├─ App/ # Frontend + backend
│ ├─ src/ # React + TypeScript app (Vite)
│ │ ├─ App.tsx
│ │ ├─ main.tsx
│ │ └─ index.css
│ ├─ server/ # Express API
│ │ ├─ models/Book.js # Mongoose Book model
│ │ ├─ routes/bookRoutes.js# API routes (GET/POST/PUT/DELETE /api/books)
│ │ └─ server.js # Express server and DB connection
│ └─ package.json # Frontend deps & scripts (Vite)
├─ README.md # <-- this file
├─ CONTRIBUTING.md
└─ LICENSE
The Book model (App/server/models/Book.js) contains:
title(String, required)author(String, required)genre(String, required)year(Number, required)status(String — enum:read | reading | to-read, defaultto-read)createdAt/updatedAt(timestamps added automatically)
- Keep your MongoDB connection string and other secrets out of version control. Add
App/server/.envlocally and never commit it. - Example
App/server/.env:
MONGODB_URI='your-mongodb-connection-string'
PORT=5000- Frontend: build with
cd App && npm run buildand deploy to Vercel, Netlify, or any static host. - Backend: deploy
App/serverto any Node host (Render, Railway, Heroku-like) and setMONGODB_URIin the host's environment. - To serve frontend from the backend, build the frontend then add Express static middleware to
server.jsand point unknown routes toindex.html.
Contributions are welcome. See CONTRIBUTING.md for guidelines. Quick contribution flow:
- Fork the repo
- Create a feature branch:
git checkout -b feature/awesome - Commit changes:
git commit -m "Add awesome feature" - Push and open a Pull Request
Please keep changes small and focused. Good first issues and documentation improvements are great places to start.
- Frontend scripts are in
App/package.json(dev, build, preview, lint, typecheck) - Backend scripts are in
App/server/package.json(start, dev)
Run linters and typecheck in the frontend as needed (npm run lint, npm run typecheck).
This project is licensed under the MIT License — see the LICENSE file for details.
If this project helped you, please give it a star ⭐
Made with ❤️ by the project contributors